diff --git a/examples/mvvmfx-cdi-starter/pom.xml b/examples/mvvmfx-cdi-starter/pom.xml index f75295800..b889ff230 100644 --- a/examples/mvvmfx-cdi-starter/pom.xml +++ b/examples/mvvmfx-cdi-starter/pom.xml @@ -1,17 +1,17 @@ + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 mvvmfx-cdi-example mvvmFX CDI Example - This example shows the usage of the mvvmFX framework with CDI Dependency Injection. + This example shows the usage of the mvvmFX framework with CDI Dependency Injection. - - + + de.saxsys - mvvmFX-examples + mvvmFX-examples 0.3.0-SNAPSHOT @@ -23,48 +23,48 @@ - - javax.inject - javax.inject - 1 - - - javax.enterprise - cdi-api - 1.1 - - - org.slf4j - slf4j-simple - 1.7.6 - + + javax.inject + javax.inject + 1 + + + javax.enterprise + cdi-api + 1.1 + + + org.slf4j + slf4j-simple + 1.7.6 + de.saxsys mvvmFX ${project.parent.version} - - de.saxsys - mvvmFX-cdi - ${project.parent.version} - - - org.jboss.weld.se - weld-se - 2.1.0.Final - - - de.saxsys - mvvmfx-complex - ${project.parent.version} - + + de.saxsys + mvvmFX-cdi + ${project.parent.version} + + + org.jboss.weld.se + weld-se + 2.1.0.Final + + + de.saxsys + mvvmfx-complex + ${project.parent.version} + junit junit 4.11 test - + diff --git a/examples/mvvmfx-cdi-starter/src/main/java/de/saxsys/jfx/Starter.java b/examples/mvvmfx-cdi-starter/src/main/java/de/saxsys/jfx/Starter.java index 85e85318e..782d595e8 100644 --- a/examples/mvvmfx-cdi-starter/src/main/java/de/saxsys/jfx/Starter.java +++ b/examples/mvvmfx-cdi-starter/src/main/java/de/saxsys/jfx/Starter.java @@ -1,40 +1,41 @@ package de.saxsys.jfx; -import de.saxsys.jfx.exampleapplication.view.maincontainer.MainContainerView; -import de.saxsys.jfx.exampleapplication.viewmodel.maincontainer.MainContainerViewModel; -import de.saxsys.jfx.mvvm.cdi.MvvmfxCdiApplication; -import de.saxsys.jfx.mvvm.viewloader.ViewLoader; -import de.saxsys.jfx.mvvm.viewloader.ViewTuple; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.stage.Stage; import javax.inject.Inject; +import de.saxsys.jfx.exampleapplication.view.maincontainer.MainContainerView; +import de.saxsys.jfx.exampleapplication.viewmodel.maincontainer.MainContainerViewModel; +import de.saxsys.jfx.mvvm.cdi.MvvmfxCdiApplication; +import de.saxsys.jfx.mvvm.viewloader.ViewLoader; +import de.saxsys.jfx.mvvm.viewloader.ViewTuple; + /** * The application entry point. * * @author manuel.mauky */ public class Starter extends MvvmfxCdiApplication { - - public static void main(String... args) { - launch(args); - } - - @Inject - private ViewLoader viewLoader; - - @Override - public void start(Stage stage) { - ViewTuple tuple = - viewLoader - .loadViewTuple(MainContainerView.class); - - Parent view = tuple.getView(); - - final Scene scene = new Scene(view); - stage.setScene(scene); - stage.show(); - } + + public static void main(String... args) { + launch(args); + } + + @Inject + private ViewLoader viewLoader; + + @Override + public void start(Stage stage) { + ViewTuple tuple = + viewLoader + .loadViewTuple(MainContainerView.class); + + Parent view = tuple.getView(); + + final Scene scene = new Scene(view); + stage.setScene(scene); + stage.show(); + } } diff --git a/examples/mvvmfx-cdi-starter/src/main/resources/META-INF/beans.xml b/examples/mvvmfx-cdi-starter/src/main/resources/META-INF/beans.xml index 472be2f28..e4a69c2a9 100644 --- a/examples/mvvmfx-cdi-starter/src/main/resources/META-INF/beans.xml +++ b/examples/mvvmfx-cdi-starter/src/main/resources/META-INF/beans.xml @@ -17,5 +17,4 @@ - diff --git a/examples/mvvmfx-complex-example/pom.xml b/examples/mvvmfx-complex-example/pom.xml index d09ae75d5..1a3e636dd 100644 --- a/examples/mvvmfx-complex-example/pom.xml +++ b/examples/mvvmfx-complex-example/pom.xml @@ -1,12 +1,12 @@ + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 mvvmfx-complex Complex Example - - + + de.saxsys - mvvmFX-examples + mvvmFX-examples 0.3.0-SNAPSHOT @@ -27,11 +27,11 @@ - - javax.inject - javax.inject - 1 - + + javax.inject + javax.inject + 1 + junit junit @@ -72,8 +72,8 @@ - - + + diff --git a/examples/mvvmfx-complex-example/src/main/java/de/saxsys/jfx/exampleapplication/model/Person.java b/examples/mvvmfx-complex-example/src/main/java/de/saxsys/jfx/exampleapplication/model/Person.java index e424028c4..14c0dd5a1 100644 --- a/examples/mvvmfx-complex-example/src/main/java/de/saxsys/jfx/exampleapplication/model/Person.java +++ b/examples/mvvmfx-complex-example/src/main/java/de/saxsys/jfx/exampleapplication/model/Person.java @@ -1,26 +1,24 @@ package de.saxsys.jfx.exampleapplication.model; import java.util.Random; - import javafx.beans.property.BooleanProperty; import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; /** - * The class represents a Person with a firstname and a lastname. It provides - * access with JavaFX Properties. + * The class represents a Person with a firstname and a lastname. It provides access with JavaFX Properties. * * @author alexander.casall * */ public class Person { - + private int technicalID; private final StringProperty firstName = new SimpleStringProperty(); private final StringProperty lastName = new SimpleStringProperty(); private final BooleanProperty male = new SimpleBooleanProperty(); - + /** * Creates a person with given name. * @@ -34,21 +32,21 @@ public Person(final String firstName, final String lastName, final boolean isMal this.lastName.set(lastName); this.male.set(isMale); } - + /** * @return firstname as {@link StringProperty} */ public StringProperty firstNameProperty() { return firstName; } - + /** * @return lastname as {@link StringProperty} */ public StringProperty lastNameProperty() { return lastName; } - + /** * @return male as {@link BooleanProperty} */ @@ -62,7 +60,7 @@ public BooleanProperty maleProperty() { public String getFirstName() { return firstNameProperty().get(); } - + /** * @see #getFirstName() * @param firstName @@ -70,21 +68,21 @@ public String getFirstName() { public void setFirstName(final String firstName) { firstNameProperty().set(firstName); } - + /** * @return lastname as {@link String} */ public String getLastName() { return lastNameProperty().get(); } - + /** * @see #getLastName() */ public void setLastName(final String lastName) { lastNameProperty().set(lastName); } - + /** * @return male as boolean */ @@ -94,7 +92,8 @@ public boolean isMale() { /** * @see #isMale() - * @param male whether the person is male + * @param male + * whether the person is male */ public void setMale(boolean male) { this.male.set(male); @@ -111,5 +110,5 @@ public int getId() { } return technicalID; } - + } diff --git a/examples/mvvmfx-complex-example/src/main/java/de/saxsys/jfx/exampleapplication/model/Repository.java b/examples/mvvmfx-complex-example/src/main/java/de/saxsys/jfx/exampleapplication/model/Repository.java index 5b9be9234..af6ba43a4 100644 --- a/examples/mvvmfx-complex-example/src/main/java/de/saxsys/jfx/exampleapplication/model/Repository.java +++ b/examples/mvvmfx-complex-example/src/main/java/de/saxsys/jfx/exampleapplication/model/Repository.java @@ -12,9 +12,9 @@ */ @Singleton public class Repository { - + List persons = new ArrayList(); - + /** * Creates the Repo. */ @@ -23,14 +23,14 @@ public Repository() { persons.add(new Person("Bernd", "Grams", true)); persons.add(new Person("Anna", "Schulze", false)); } - + /** * @return available {@link Person}s */ public List getPersons() { return persons; } - + /** * Gets a Person.s * @@ -44,5 +44,5 @@ public Person getPersonById(final int id) { return person; return null; } - + } diff --git a/examples/mvvmfx-complex-example/src/main/java/de/saxsys/jfx/exampleapplication/view/maincontainer/MainContainerView.java b/examples/mvvmfx-complex-example/src/main/java/de/saxsys/jfx/exampleapplication/view/maincontainer/MainContainerView.java index 052b47e6d..3fd5e2f41 100644 --- a/examples/mvvmfx-complex-example/src/main/java/de/saxsys/jfx/exampleapplication/view/maincontainer/MainContainerView.java +++ b/examples/mvvmfx-complex-example/src/main/java/de/saxsys/jfx/exampleapplication/view/maincontainer/MainContainerView.java @@ -4,9 +4,6 @@ import java.util.HashMap; import java.util.Map; import java.util.ResourceBundle; - -import de.saxsys.jfx.mvvm.api.FxmlView; -import de.saxsys.jfx.mvvm.api.InjectViewModel; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.fxml.FXML; @@ -20,99 +17,99 @@ 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.jfx.mvvm.api.FxmlView; +import de.saxsys.jfx.mvvm.api.InjectViewModel; +import de.saxsys.jfx.mvvm.api.ViewModel; import de.saxsys.jfx.mvvm.base.view.View; import de.saxsys.jfx.mvvm.base.view.util.viewlist.ViewListCellFactory; -import de.saxsys.jfx.mvvm.api.ViewModel; import de.saxsys.jfx.mvvm.notifications.NotificationCenter; import de.saxsys.jfx.mvvm.notifications.NotificationObserver; import de.saxsys.jfx.mvvm.viewloader.ViewLoader; import de.saxsys.jfx.mvvm.viewloader.ViewTuple; /** - * Main View which creates the necessary subviews, and manages them. Does not - * need a concrete Viewmodel, so it is typed with the inferface. Have a careful - * look on the FXML file to see, how to include different views into a - * MasterView. + * Main View which creates the necessary subviews, and manages them. Does not need a concrete Viewmodel, so it is typed + * with the inferface. Have a careful look on the FXML file to see, how to include different views into a MasterView. */ public class MainContainerView implements FxmlView, Initializable { - + @FXML // Injection of the login which is declared in the FXML File private StackPane loginView; // Value injected by FXMLLoader - + @FXML // Inject the Code behind instance of the loginView by using the // nameconvention ...Controller private PersonLoginView loginViewController; - + @FXML // Inject the Code behind instance of the ListView private ListView personWelcomeListView; - + @Inject // ViewLoder private ViewLoader viewLoader; - + @Inject // Notification Center private NotificationCenter notificationCenter; - - - @InjectViewModel - private MainContainerViewModel viewModel; - - - private Map> viewMap = new HashMap<>(); - - @Override - public void initialize(URL url, ResourceBundle resourceBundle) { - // Listen for close notifications - notificationCenter.addObserverForName("hidePersonWelcome", - new NotificationObserver() { - @Override - public void receivedNotification(String key, - Object... objects) { - int personIdToHide = (int) objects[0]; - viewModel.displayedPersonsProperty().remove( - new Integer(personIdToHide)); - } - }); - - // When the login button of the loginView, the pickedPersonProperty is - // going to have the index of the selected person - loginViewController.getViewModel().loggedInPersonIdProperty() - .addListener(new ChangeListener() { - @Override - public void changed(ObservableValue arg0, - Number oldValue, Number newValue) { - int id = newValue.intValue(); - viewModel.displayedPersonsProperty().add(id); - } - }); - - // Configure List with views - personWelcomeListView.setCellFactory(new ViewListCellFactory() { - @Override - public ViewTuple map(Integer element) { - if(!viewMap.containsKey(element)) { - ViewTuple loadedViewTuple - = viewLoader - .loadViewTuple(PersonWelcomeView.class); - - PersonWelcomeView codeBehind = loadedViewTuple.getCodeBehind(); - - codeBehind.getViewModel() - .setPersonId(element); - - viewMap.put(element, loadedViewTuple); - } - - return viewMap.get(element); - } - }); - - // Bind list - personWelcomeListView.itemsProperty().bind( - viewModel.displayedPersonsProperty()); - } + + + @InjectViewModel + private MainContainerViewModel viewModel; + + + private Map> viewMap = new HashMap<>(); + + @Override + public void initialize(URL url, ResourceBundle resourceBundle) { + // Listen for close notifications + notificationCenter.addObserverForName("hidePersonWelcome", + new NotificationObserver() { + @Override + public void receivedNotification(String key, + Object... objects) { + int personIdToHide = (int) objects[0]; + viewModel.displayedPersonsProperty().remove( + new Integer(personIdToHide)); + } + }); + + // When the login button of the loginView, the pickedPersonProperty is + // going to have the index of the selected person + loginViewController.getViewModel().loggedInPersonIdProperty() + .addListener(new ChangeListener() { + @Override + public void changed(ObservableValue arg0, + Number oldValue, Number newValue) { + int id = newValue.intValue(); + viewModel.displayedPersonsProperty().add(id); + } + }); + + // Configure List with views + personWelcomeListView.setCellFactory(new ViewListCellFactory() { + @Override + public ViewTuple map(Integer element) { + if (!viewMap.containsKey(element)) { + ViewTuple loadedViewTuple + = viewLoader + .loadViewTuple(PersonWelcomeView.class); + + PersonWelcomeView codeBehind = loadedViewTuple.getCodeBehind(); + + codeBehind.getViewModel() + .setPersonId(element); + + viewMap.put(element, loadedViewTuple); + } + + return viewMap.get(element); + } + }); + + // Bind list + personWelcomeListView.itemsProperty().bind( + viewModel.displayedPersonsProperty()); + } } diff --git a/examples/mvvmfx-complex-example/src/main/java/de/saxsys/jfx/exampleapplication/view/personlogin/PersonLoginView.java b/examples/mvvmfx-complex-example/src/main/java/de/saxsys/jfx/exampleapplication/view/personlogin/PersonLoginView.java index f41dd5fae..f7f042fec 100644 --- a/examples/mvvmfx-complex-example/src/main/java/de/saxsys/jfx/exampleapplication/view/personlogin/PersonLoginView.java +++ b/examples/mvvmfx-complex-example/src/main/java/de/saxsys/jfx/exampleapplication/view/personlogin/PersonLoginView.java @@ -1,8 +1,7 @@ package de.saxsys.jfx.exampleapplication.view.personlogin; -import de.saxsys.jfx.exampleapplication.viewmodel.personlogin.PersonLoginViewModel; -import de.saxsys.jfx.mvvm.api.FxmlView; -import de.saxsys.jfx.mvvm.api.InjectViewModel; +import java.net.URL; +import java.util.ResourceBundle; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.event.ActionEvent; @@ -10,49 +9,50 @@ import javafx.fxml.Initializable; import javafx.scene.control.ChoiceBox; -import java.net.URL; -import java.util.ResourceBundle; +import de.saxsys.jfx.exampleapplication.viewmodel.personlogin.PersonLoginViewModel; +import de.saxsys.jfx.mvvm.api.FxmlView; +import de.saxsys.jfx.mvvm.api.InjectViewModel; /** - * Code behind the fxml for visualization of the {@link PersonLoginView}. The view binds to the properties of the {@link - * PersonLoginViewModel}. + * Code behind the fxml for visualization of the {@link PersonLoginView}. The view binds to the properties of the + * {@link PersonLoginViewModel}. * * @author alexander.casall */ public class PersonLoginView implements FxmlView, Initializable { - - @FXML - // Injection of the person choiceBox which is declared in the FXML File - private ChoiceBox personsChoiceBox; - - - @InjectViewModel - private PersonLoginViewModel viewModel; - - @FXML - void loginButtonPressed(final ActionEvent event) { - viewModel.login(); - } - - - public PersonLoginViewModel getViewModel() { - return viewModel; - } - - @Override - public void initialize(URL url, ResourceBundle resourceBundle) { - personsChoiceBox.itemsProperty() - .bind(viewModel.selectablePersonsProperty() - .stringListProperty()); - - personsChoiceBox.getSelectionModel().selectedIndexProperty() - .addListener(new ChangeListener() { - @Override - public void changed(ObservableValue arg0, - Number oldVal, Number newVal) { - viewModel.selectablePersonsProperty().select( - newVal.intValue()); - } - }); - } + + @FXML + // Injection of the person choiceBox which is declared in the FXML File + private ChoiceBox personsChoiceBox; + + + @InjectViewModel + private PersonLoginViewModel viewModel; + + @FXML + void loginButtonPressed(final ActionEvent event) { + viewModel.login(); + } + + + public PersonLoginViewModel getViewModel() { + return viewModel; + } + + @Override + public void initialize(URL url, ResourceBundle resourceBundle) { + personsChoiceBox.itemsProperty() + .bind(viewModel.selectablePersonsProperty() + .stringListProperty()); + + personsChoiceBox.getSelectionModel().selectedIndexProperty() + .addListener(new ChangeListener() { + @Override + public void changed(ObservableValue arg0, + Number oldVal, Number newVal) { + viewModel.selectablePersonsProperty().select( + newVal.intValue()); + } + }); + } } diff --git a/examples/mvvmfx-complex-example/src/main/java/de/saxsys/jfx/exampleapplication/view/personwelcome/PersonWelcomeView.java b/examples/mvvmfx-complex-example/src/main/java/de/saxsys/jfx/exampleapplication/view/personwelcome/PersonWelcomeView.java index d83cef486..5c207dada 100644 --- a/examples/mvvmfx-complex-example/src/main/java/de/saxsys/jfx/exampleapplication/view/personwelcome/PersonWelcomeView.java +++ b/examples/mvvmfx-complex-example/src/main/java/de/saxsys/jfx/exampleapplication/view/personwelcome/PersonWelcomeView.java @@ -3,8 +3,6 @@ import java.net.URL; import java.util.ResourceBundle; -import de.saxsys.jfx.mvvm.api.FxmlView; -import de.saxsys.jfx.mvvm.api.InjectViewModel; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.Initializable; @@ -13,43 +11,44 @@ import javax.inject.Inject; import de.saxsys.jfx.exampleapplication.viewmodel.personwelcome.PersonWelcomeViewModel; -import de.saxsys.jfx.mvvm.base.view.View; +import de.saxsys.jfx.mvvm.api.FxmlView; +import de.saxsys.jfx.mvvm.api.InjectViewModel; import de.saxsys.jfx.mvvm.notifications.NotificationCenter; /** - * Code behind the fxml for visualization of the PersonWelcomeViewModel. The - * view binds to the property of the {@link PersonWelcomeViewModel}. + * Code behind the fxml for visualization of the PersonWelcomeViewModel. The view binds to the property of the + * {@link PersonWelcomeViewModel}. * * @author alexander.casall */ -public class PersonWelcomeView implements FxmlView, Initializable{ - +public class PersonWelcomeView implements FxmlView, Initializable { + @FXML // Injection of the label which is declared in the FXML File and shows the // welcome message private Label welcomeLabel; - + @Inject private NotificationCenter notificationCenter; - - @InjectViewModel - private PersonWelcomeViewModel viewModel; - + + @InjectViewModel + private PersonWelcomeViewModel viewModel; + @FXML // Handler for Button[Button[id=null, styleClass=button]] onAction public void closeApplicationButtonPressed(ActionEvent event) { // MainContainerView.java will handle it notificationCenter.postNotification("hidePersonWelcome", viewModel - .getPersonId()); + .getPersonId()); + } + + public PersonWelcomeViewModel getViewModel() { + return viewModel; + } + + @Override + public void initialize(URL url, ResourceBundle resourceBundle) { + welcomeLabel.textProperty() + .bind(viewModel.welcomeStringProperty()); } - - public PersonWelcomeViewModel getViewModel() { - return viewModel; - } - - @Override - public void initialize(URL url, ResourceBundle resourceBundle) { - welcomeLabel.textProperty() - .bind(viewModel.welcomeStringProperty()); - } } diff --git a/examples/mvvmfx-complex-example/src/main/java/de/saxsys/jfx/exampleapplication/viewmodel/maincontainer/MainContainerViewModel.java b/examples/mvvmfx-complex-example/src/main/java/de/saxsys/jfx/exampleapplication/viewmodel/maincontainer/MainContainerViewModel.java index 3f37f9ed4..f4c7a82ba 100644 --- a/examples/mvvmfx-complex-example/src/main/java/de/saxsys/jfx/exampleapplication/viewmodel/maincontainer/MainContainerViewModel.java +++ b/examples/mvvmfx-complex-example/src/main/java/de/saxsys/jfx/exampleapplication/viewmodel/maincontainer/MainContainerViewModel.java @@ -6,16 +6,16 @@ import de.saxsys.jfx.mvvm.api.ViewModel; public class MainContainerViewModel implements ViewModel { - + private ListProperty displayedPersons = new SimpleListProperty<>( FXCollections. observableArrayList()); - + public MainContainerViewModel() { - + } - + public ListProperty displayedPersonsProperty() { return displayedPersons; } - + } diff --git a/examples/mvvmfx-complex-example/src/main/java/de/saxsys/jfx/exampleapplication/viewmodel/personlogin/PersonLoginViewModel.java b/examples/mvvmfx-complex-example/src/main/java/de/saxsys/jfx/exampleapplication/viewmodel/personlogin/PersonLoginViewModel.java index b085ecdab..c5e5c4c3e 100644 --- a/examples/mvvmfx-complex-example/src/main/java/de/saxsys/jfx/exampleapplication/viewmodel/personlogin/PersonLoginViewModel.java +++ b/examples/mvvmfx-complex-example/src/main/java/de/saxsys/jfx/exampleapplication/viewmodel/personlogin/PersonLoginViewModel.java @@ -14,9 +14,8 @@ import de.saxsys.jfx.mvvm.base.viewmodel.util.itemlist.SelectableStringList; /** - * ViewModel for a login view for the persons. It provides the data which should - * be visualized in the frontend e.g. the list of persons in string - * representations. The tests for it can be written first. Have a look on + * ViewModel for a login view for the persons. It provides the data which should be visualized in the frontend e.g. the + * list of persons in string representations. The tests for it can be written first. Have a look on * PersonLoginViewModelTest. * * @author alexander.casall @@ -24,12 +23,12 @@ */ public class PersonLoginViewModel implements ViewModel { - + // Properties which are used by the view. private final SelectableItemList selectablePersons; - + private final IntegerProperty loggedInPersonId = new SimpleIntegerProperty(); - + @Inject public PersonLoginViewModel(Repository repository) { ModelToStringFunction personMapper = new ModelToStringFunction() { @@ -42,7 +41,7 @@ public String apply(Person person) { FXCollections.observableArrayList(repository.getPersons()), personMapper); } - + /** * Persons in string representation. * @@ -51,7 +50,7 @@ public String apply(Person person) { public SelectableStringList selectablePersonsProperty() { return selectablePersons; } - + /** * Person which is logged in. * @@ -60,7 +59,7 @@ public SelectableStringList selectablePersonsProperty() { public IntegerProperty loggedInPersonIdProperty() { return loggedInPersonId; } - + /** * Action when the login button was clicked. */ diff --git a/examples/mvvmfx-complex-example/src/main/java/de/saxsys/jfx/exampleapplication/viewmodel/personwelcome/PersonWelcomeViewModel.java b/examples/mvvmfx-complex-example/src/main/java/de/saxsys/jfx/exampleapplication/viewmodel/personwelcome/PersonWelcomeViewModel.java index 146718618..9e29d58ae 100644 --- a/examples/mvvmfx-complex-example/src/main/java/de/saxsys/jfx/exampleapplication/viewmodel/personwelcome/PersonWelcomeViewModel.java +++ b/examples/mvvmfx-complex-example/src/main/java/de/saxsys/jfx/exampleapplication/viewmodel/personwelcome/PersonWelcomeViewModel.java @@ -1,35 +1,32 @@ package de.saxsys.jfx.exampleapplication.viewmodel.personwelcome; -import java.util.concurrent.Callable; - import javafx.beans.binding.Bindings; import javafx.beans.binding.StringBinding; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; +import javax.inject.Inject; + import de.saxsys.jfx.exampleapplication.model.Person; import de.saxsys.jfx.exampleapplication.model.Repository; import de.saxsys.jfx.mvvm.api.ViewModel; -import javax.inject.Inject; - /** - * ViewModel for a welcome view for a person. It provides the data which should - * be visualized in the frontend. The tests for it can be written first. Have a - * look on PersonWelcomeViewModelTest. + * ViewModel for a welcome view for a person. It provides the data which should be visualized in the frontend. The tests + * for it can be written first. Have a look on PersonWelcomeViewModelTest. * * @author alexander.casall * */ public class PersonWelcomeViewModel implements ViewModel { - + private Repository repository; - + // Properties which are used by the view. private final StringProperty welcomeString = new SimpleStringProperty(); - + private Person person; - + /** * Create a {@link PersonWelcomeViewModel}. * @@ -40,7 +37,7 @@ public class PersonWelcomeViewModel implements ViewModel { public PersonWelcomeViewModel(Repository repository) { this.repository = repository; } - + /** * Provides the the concated string. * @@ -49,7 +46,7 @@ public PersonWelcomeViewModel(Repository repository) { public StringProperty welcomeStringProperty() { return welcomeString; } - + /** * Set Person id for the screen * @@ -58,12 +55,12 @@ public StringProperty welcomeStringProperty() { */ public void setPersonId(int personId) { person = repository.getPersonById(personId); - StringBinding salutationBinding = Bindings.when(person.maleProperty()).then("Herr ").otherwise("Frau "); + StringBinding salutationBinding = Bindings.when(person.maleProperty()).then("Herr ").otherwise("Frau "); welcomeString.bind(Bindings.concat("Willkommen ", salutationBinding, person.lastNameProperty(), ", oder wollen Sie ", person.firstNameProperty(), " genannt werden?")); } - + /** * Returns the id of the displayed person. * diff --git a/examples/mvvmfx-complex-example/src/main/resources/META-INF/beans.xml b/examples/mvvmfx-complex-example/src/main/resources/META-INF/beans.xml index 472be2f28..e4a69c2a9 100644 --- a/examples/mvvmfx-complex-example/src/main/resources/META-INF/beans.xml +++ b/examples/mvvmfx-complex-example/src/main/resources/META-INF/beans.xml @@ -17,5 +17,4 @@ - diff --git a/examples/mvvmfx-complex-example/src/main/resources/de/saxsys/jfx/exampleapplication/view/maincontainer/MainContainerView.fxml b/examples/mvvmfx-complex-example/src/main/resources/de/saxsys/jfx/exampleapplication/view/maincontainer/MainContainerView.fxml index 020a83d94..9d4cd3359 100644 --- a/examples/mvvmfx-complex-example/src/main/resources/de/saxsys/jfx/exampleapplication/view/maincontainer/MainContainerView.fxml +++ b/examples/mvvmfx-complex-example/src/main/resources/de/saxsys/jfx/exampleapplication/view/maincontainer/MainContainerView.fxml @@ -1,19 +1,18 @@ - - - + + - - - - - - - - - - - - + + + + + + + + + + + diff --git a/examples/mvvmfx-complex-example/src/main/resources/de/saxsys/jfx/exampleapplication/view/personlogin/PersonLoginView.fxml b/examples/mvvmfx-complex-example/src/main/resources/de/saxsys/jfx/exampleapplication/view/personlogin/PersonLoginView.fxml index c7634d2d5..366d9f676 100644 --- a/examples/mvvmfx-complex-example/src/main/resources/de/saxsys/jfx/exampleapplication/view/personlogin/PersonLoginView.fxml +++ b/examples/mvvmfx-complex-example/src/main/resources/de/saxsys/jfx/exampleapplication/view/personlogin/PersonLoginView.fxml @@ -1,33 +1,35 @@ - - - - + + + + - - - - - - - - - - - - - - - - - -