From b33e9fcd0771e01dd315960fb6c4bc7d481be857 Mon Sep 17 00:00:00 2001 From: Johannes Pfrang Date: Fri, 3 Jun 2016 13:18:27 +0200 Subject: [PATCH 01/57] Fix defaulValue not getting applied --- .../main/java/de/saxsys/mvvmfx/utils/mapping/ModelWrapper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mvvmfx/src/main/java/de/saxsys/mvvmfx/utils/mapping/ModelWrapper.java b/mvvmfx/src/main/java/de/saxsys/mvvmfx/utils/mapping/ModelWrapper.java index 06704b8d8..7a4287bfd 100644 --- a/mvvmfx/src/main/java/de/saxsys/mvvmfx/utils/mapping/ModelWrapper.java +++ b/mvvmfx/src/main/java/de/saxsys/mvvmfx/utils/mapping/ModelWrapper.java @@ -811,7 +811,7 @@ public StringProperty field(StringPropertyAccessor accessor) { * @return The wrapped property instance. */ public StringProperty field(StringPropertyAccessor accessor, String defaultValue) { - return add(new FxPropertyField<>(accessor::apply, SimpleStringProperty::new)); + return add(new FxPropertyField<>(accessor::apply, defaultValue, SimpleStringProperty::new)); } From 8a59a13d92780fcd4b770b987aeaec19b99d76f4 Mon Sep 17 00:00:00 2001 From: Johannes Pfrang Date: Fri, 3 Jun 2016 14:01:20 +0200 Subject: [PATCH 02/57] Early return in calculateDifferenceFlag() --- .../de/saxsys/mvvmfx/utils/mapping/ModelWrapper.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/mvvmfx/src/main/java/de/saxsys/mvvmfx/utils/mapping/ModelWrapper.java b/mvvmfx/src/main/java/de/saxsys/mvvmfx/utils/mapping/ModelWrapper.java index 06704b8d8..97c417755 100644 --- a/mvvmfx/src/main/java/de/saxsys/mvvmfx/utils/mapping/ModelWrapper.java +++ b/mvvmfx/src/main/java/de/saxsys/mvvmfx/utils/mapping/ModelWrapper.java @@ -702,11 +702,13 @@ private void propertyWasChanged() { private void calculateDifferenceFlag() { if (model.get() != null) { - final Optional> optional = fields.stream() - .filter(field -> field.isDifferent(model.get())) - .findAny(); - - diffFlag.set(optional.isPresent()); + for (final PropertyField field : fields) { + if (field.isDifferent(model.get())) { + diffFlag.set(true); + return; + } + } + diffFlag.set(false); } } From 8679100b9d3715ed72292a286c41c62fac53d241 Mon Sep 17 00:00:00 2001 From: Manuel Mauky Date: Fri, 3 Jun 2016 14:38:06 +0200 Subject: [PATCH 03/57] Update version number to 1.6.0-SNAPSHOT on develop branch to begin next dev cycle #392 --- examples/books-example/pom.xml | 2 +- examples/contacts-example/pom.xml | 2 +- examples/mini-examples/fx-root-example/pom.xml | 2 +- examples/mini-examples/helloworld-without-fxml/pom.xml | 2 +- examples/mini-examples/helloworld/pom.xml | 2 +- examples/mini-examples/pom.xml | 2 +- examples/mini-examples/scopes-example/pom.xml | 2 +- examples/mini-examples/synchronizefx-example/pom.xml | 2 +- examples/mini-examples/welcome-example/pom.xml | 2 +- examples/pom.xml | 2 +- examples/todomvc-example/pom.xml | 2 +- mvvmfx-archetype/pom.xml | 2 +- mvvmfx-archetype/src/main/resources/archetype-resources/pom.xml | 2 +- mvvmfx-cdi/pom.xml | 2 +- mvvmfx-guice/pom.xml | 2 +- mvvmfx-testing-utils/pom.xml | 2 +- mvvmfx-utils/pom.xml | 2 +- mvvmfx/pom.xml | 2 +- pom.xml | 2 +- 19 files changed, 19 insertions(+), 19 deletions(-) diff --git a/examples/books-example/pom.xml b/examples/books-example/pom.xml index bbe285bc4..a2eb93d39 100644 --- a/examples/books-example/pom.xml +++ b/examples/books-example/pom.xml @@ -5,7 +5,7 @@ de.saxsys.mvvmfx examples - 1.5.0 + 1.6.0-SNAPSHOT 4.0.0 diff --git a/examples/contacts-example/pom.xml b/examples/contacts-example/pom.xml index 654c2b88b..7d312d1fd 100644 --- a/examples/contacts-example/pom.xml +++ b/examples/contacts-example/pom.xml @@ -6,7 +6,7 @@ de.saxsys.mvvmfx examples - 1.5.0 + 1.6.0-SNAPSHOT contacts-example diff --git a/examples/mini-examples/fx-root-example/pom.xml b/examples/mini-examples/fx-root-example/pom.xml index 28a92fe6e..30832412d 100644 --- a/examples/mini-examples/fx-root-example/pom.xml +++ b/examples/mini-examples/fx-root-example/pom.xml @@ -5,7 +5,7 @@ mini-examples de.saxsys.mvvmfx - 1.5.0 + 1.6.0-SNAPSHOT 4.0.0 diff --git a/examples/mini-examples/helloworld-without-fxml/pom.xml b/examples/mini-examples/helloworld-without-fxml/pom.xml index 71f3019c6..ee8971bdd 100644 --- a/examples/mini-examples/helloworld-without-fxml/pom.xml +++ b/examples/mini-examples/helloworld-without-fxml/pom.xml @@ -5,7 +5,7 @@ mini-examples de.saxsys.mvvmfx - 1.5.0 + 1.6.0-SNAPSHOT 4.0.0 diff --git a/examples/mini-examples/helloworld/pom.xml b/examples/mini-examples/helloworld/pom.xml index 9d262bf5e..ae66227ca 100644 --- a/examples/mini-examples/helloworld/pom.xml +++ b/examples/mini-examples/helloworld/pom.xml @@ -5,7 +5,7 @@ mini-examples de.saxsys.mvvmfx - 1.5.0 + 1.6.0-SNAPSHOT 4.0.0 diff --git a/examples/mini-examples/pom.xml b/examples/mini-examples/pom.xml index af8292bfb..538f859a2 100644 --- a/examples/mini-examples/pom.xml +++ b/examples/mini-examples/pom.xml @@ -5,7 +5,7 @@ examples de.saxsys.mvvmfx - 1.5.0 + 1.6.0-SNAPSHOT 4.0.0 pom diff --git a/examples/mini-examples/scopes-example/pom.xml b/examples/mini-examples/scopes-example/pom.xml index 1296d55ad..8ede658e4 100644 --- a/examples/mini-examples/scopes-example/pom.xml +++ b/examples/mini-examples/scopes-example/pom.xml @@ -5,7 +5,7 @@ mini-examples de.saxsys.mvvmfx - 1.5.0 + 1.6.0-SNAPSHOT 4.0.0 diff --git a/examples/mini-examples/synchronizefx-example/pom.xml b/examples/mini-examples/synchronizefx-example/pom.xml index dc4a396b2..0e17e1cc5 100644 --- a/examples/mini-examples/synchronizefx-example/pom.xml +++ b/examples/mini-examples/synchronizefx-example/pom.xml @@ -5,7 +5,7 @@ mini-examples de.saxsys.mvvmfx - 1.5.0 + 1.6.0-SNAPSHOT 4.0.0 diff --git a/examples/mini-examples/welcome-example/pom.xml b/examples/mini-examples/welcome-example/pom.xml index 2f99a4812..fea5f1018 100644 --- a/examples/mini-examples/welcome-example/pom.xml +++ b/examples/mini-examples/welcome-example/pom.xml @@ -5,7 +5,7 @@ mini-examples de.saxsys.mvvmfx - 1.5.0 + 1.6.0-SNAPSHOT 4.0.0 diff --git a/examples/pom.xml b/examples/pom.xml index 712070df6..72e1551de 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -5,7 +5,7 @@ de.saxsys mvvmfx-parent - 1.5.0 + 1.6.0-SNAPSHOT de.saxsys.mvvmfx diff --git a/examples/todomvc-example/pom.xml b/examples/todomvc-example/pom.xml index bc97398a0..3e17c85af 100644 --- a/examples/todomvc-example/pom.xml +++ b/examples/todomvc-example/pom.xml @@ -5,7 +5,7 @@ de.saxsys.mvvmfx examples - 1.5.0 + 1.6.0-SNAPSHOT 4.0.0 diff --git a/mvvmfx-archetype/pom.xml b/mvvmfx-archetype/pom.xml index d4a713ee7..acadb0b88 100644 --- a/mvvmfx-archetype/pom.xml +++ b/mvvmfx-archetype/pom.xml @@ -5,7 +5,7 @@ de.saxsys mvvmfx-parent - 1.5.0 + 1.6.0-SNAPSHOT diff --git a/mvvmfx-archetype/src/main/resources/archetype-resources/pom.xml b/mvvmfx-archetype/src/main/resources/archetype-resources/pom.xml index dd84e1e26..1c4e44e7d 100644 --- a/mvvmfx-archetype/src/main/resources/archetype-resources/pom.xml +++ b/mvvmfx-archetype/src/main/resources/archetype-resources/pom.xml @@ -16,7 +16,7 @@ de.saxsys mvvmfx-parent - 1.5.0 + 1.6.0-SNAPSHOT pom import diff --git a/mvvmfx-cdi/pom.xml b/mvvmfx-cdi/pom.xml index a36e1cf40..c6b0e1012 100644 --- a/mvvmfx-cdi/pom.xml +++ b/mvvmfx-cdi/pom.xml @@ -20,7 +20,7 @@ de.saxsys mvvmfx-parent - 1.5.0 + 1.6.0-SNAPSHOT mvvmfx-cdi diff --git a/mvvmfx-guice/pom.xml b/mvvmfx-guice/pom.xml index d12b86a71..da89d7530 100644 --- a/mvvmfx-guice/pom.xml +++ b/mvvmfx-guice/pom.xml @@ -20,7 +20,7 @@ de.saxsys mvvmfx-parent - 1.5.0 + 1.6.0-SNAPSHOT mvvmfx-guice diff --git a/mvvmfx-testing-utils/pom.xml b/mvvmfx-testing-utils/pom.xml index 4f8cb81ed..332ba5f72 100644 --- a/mvvmfx-testing-utils/pom.xml +++ b/mvvmfx-testing-utils/pom.xml @@ -5,7 +5,7 @@ mvvmfx-parent de.saxsys - 1.5.0 + 1.6.0-SNAPSHOT 4.0.0 diff --git a/mvvmfx-utils/pom.xml b/mvvmfx-utils/pom.xml index bd0323a13..ea8a49a4e 100644 --- a/mvvmfx-utils/pom.xml +++ b/mvvmfx-utils/pom.xml @@ -5,7 +5,7 @@ mvvmfx-parent de.saxsys - 1.5.0 + 1.6.0-SNAPSHOT 4.0.0 diff --git a/mvvmfx/pom.xml b/mvvmfx/pom.xml index d00ce1c44..706000c6e 100644 --- a/mvvmfx/pom.xml +++ b/mvvmfx/pom.xml @@ -20,7 +20,7 @@ de.saxsys mvvmfx-parent - 1.5.0 + 1.6.0-SNAPSHOT mvvmfx diff --git a/pom.xml b/pom.xml index cea6c6657..12714dafd 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ de.saxsys mvvmfx-parent pom - 1.5.0 + 1.6.0-SNAPSHOT mvvmFX parent Application Framework for MVVM with JavaFX. http://www.saxsys.de From 95c613c791d58fe763f2bcbbae8ccc2eb54e219e Mon Sep 17 00:00:00 2001 From: Johannes Pfrang Date: Fri, 3 Jun 2016 16:22:05 +0200 Subject: [PATCH 04/57] fix typo --- .../main/java/de/saxsys/mvvmfx/utils/mapping/ModelWrapper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mvvmfx/src/main/java/de/saxsys/mvvmfx/utils/mapping/ModelWrapper.java b/mvvmfx/src/main/java/de/saxsys/mvvmfx/utils/mapping/ModelWrapper.java index 06704b8d8..0cbae2b79 100644 --- a/mvvmfx/src/main/java/de/saxsys/mvvmfx/utils/mapping/ModelWrapper.java +++ b/mvvmfx/src/main/java/de/saxsys/mvvmfx/utils/mapping/ModelWrapper.java @@ -1231,7 +1231,7 @@ private > R addIdentified(String fieldName, PropertyFie * change the data of the model instance directly, this property won't turn to true. * * - * @return a reay-only property indicating a difference between model and wrapper. + * @return a read-only property indicating a difference between model and wrapper. */ public ReadOnlyBooleanProperty differentProperty() { return diffFlag.getReadOnlyProperty(); From f4270ce8eeaa576513e9b1948e7760ad6970ce6c Mon Sep 17 00:00:00 2001 From: Manuel Mauky Date: Mon, 6 Jun 2016 16:38:57 +0200 Subject: [PATCH 05/57] fix contacts example. --- .../contacts/ui/detail/DetailViewModel.java | 42 ++++------ .../ui/master/MasterTableViewModel.java | 81 ++++++------------- .../contacts/ui/master/MasterViewModel.java | 15 ++-- .../ui/master/MasterTableViewModelTest.java | 2 +- 4 files changed, 46 insertions(+), 94 deletions(-) diff --git a/examples/contacts-example/src/main/java/de/saxsys/mvvmfx/examples/contacts/ui/detail/DetailViewModel.java b/examples/contacts-example/src/main/java/de/saxsys/mvvmfx/examples/contacts/ui/detail/DetailViewModel.java index 29ec36df2..cdb82121e 100644 --- a/examples/contacts-example/src/main/java/de/saxsys/mvvmfx/examples/contacts/ui/detail/DetailViewModel.java +++ b/examples/contacts-example/src/main/java/de/saxsys/mvvmfx/examples/contacts/ui/detail/DetailViewModel.java @@ -4,6 +4,9 @@ import java.time.LocalDate; import java.time.format.DateTimeFormatter; +import java.util.Objects; +import java.util.Optional; +import java.util.StringJoiner; import javax.inject.Inject; @@ -26,6 +29,7 @@ import javafx.beans.property.ReadOnlyObjectProperty; import javafx.beans.property.ReadOnlyStringProperty; import javafx.beans.property.ReadOnlyStringWrapper; +import javafx.beans.value.ObservableValue; @ScopeProvider(scopes = ContactDialogScope.class) public class DetailViewModel implements ViewModel { @@ -101,19 +105,17 @@ protected void action() throws Exception { private void createBindingsForLabels(ReadOnlyObjectProperty contactProperty) { name.bind(emptyStringOnNull(map(contactProperty, contact -> { - StringBuilder result = new StringBuilder(); + StringJoiner joiner = new StringJoiner(" "); - String title = contact.getTitle(); - if (title != null && !title.trim().isEmpty()) { - result.append(title); - result.append(" "); - } + Optional.ofNullable(contact.getTitle()) + .filter(Objects::nonNull) + .filter(s -> !s.trim().isEmpty()) + .ifPresent(joiner::add); - result.append(contact.getFirstname()); - result.append(" "); - result.append(contact.getLastname()); + joiner.add(contact.getFirstname()); + joiner.add(contact.getLastname()); - return result.toString(); + return joiner.toString(); }))); email.bind(emptyStringOnNull(map(contactProperty, Contact::getEmailAddress))); @@ -184,12 +186,12 @@ private void createBindingsForLabels(ReadOnlyObjectProperty contactProp * string is used for the returned binding. Otherwise the value of the * source binding is used. */ - private StringBinding emptyStringOnNull(ObjectBinding source) { + private StringBinding emptyStringOnNull(ObservableValue source) { return Bindings.createStringBinding(() -> { - if (source.get() == null) { + if (source.getValue() == null) { return ""; } else { - return source.get(); + return source.getValue(); } }, source); } @@ -242,20 +244,6 @@ public ReadOnlyStringProperty countrySubdivisionLabelTextProperty() { return countrySubdivision.getReadOnlyProperty(); } - private String trimString(String string) { - if (string == null || string.trim().isEmpty()) { - return ""; - } - return string; - } - - private String trimStringWithPostfix(String string, String append) { - if (string == null || string.trim().isEmpty()) { - return ""; - } - return string + append; - } - private Contact getSelectedContactFromScope() { return getSelectedContactPropertyFromScope().get(); } diff --git a/examples/contacts-example/src/main/java/de/saxsys/mvvmfx/examples/contacts/ui/master/MasterTableViewModel.java b/examples/contacts-example/src/main/java/de/saxsys/mvvmfx/examples/contacts/ui/master/MasterTableViewModel.java index 9d0cc17c7..d55dc846f 100644 --- a/examples/contacts-example/src/main/java/de/saxsys/mvvmfx/examples/contacts/ui/master/MasterTableViewModel.java +++ b/examples/contacts-example/src/main/java/de/saxsys/mvvmfx/examples/contacts/ui/master/MasterTableViewModel.java @@ -13,85 +13,50 @@ public class MasterTableViewModel { - private final String id; - private final IntegerProperty age = new SimpleIntegerProperty(); - private final ModelWrapper contactWrapper = new ModelWrapper<>(); + private Contact contact; public MasterTableViewModel(Contact contact) { - id = contact.getId(); - contactWrapper.set(contact); - contactWrapper.reload(); - - if (contact.getBirthday() != null) { - age.set((int) ChronoUnit.YEARS.between(contact.getBirthday(), LocalDate.now(CentralClock.getClock()))); - } - } - - @Override - public boolean equals(Object obj) { - - if (obj == null) { - return false; - } - - if (obj == this) { - return true; - } - - if (!(obj instanceof MasterTableViewModel)) { - return false; - } - - MasterTableViewModel other = (MasterTableViewModel) obj; - - return other.getId().equals(this.getId()); - } - - @Override - public int hashCode() { - return this.getId().hashCode(); + this.contact = contact; } public String getId() { - return id; + return contact.getId(); } - public StringProperty firstnameProperty() { - return contactWrapper.field("firstname", Contact::getFirstname, Contact::setFirstname); + public String getFirstname() { + return contact.getFirstname(); } - public StringProperty lastnameProperty() { - return contactWrapper.field("lastname", Contact::getLastname, Contact::setLastname); + public String getLastname() { + return contact.getLastname(); } - public StringProperty titleProperty() { - return contactWrapper.field("title", Contact::getTitle, Contact::setTitle); + public Integer getAge(){ + if (contact.getBirthday() == null) { + return null; + } else { + return (int) ChronoUnit.YEARS.between(contact.getBirthday(), LocalDate.now(CentralClock.getClock())); + } } - public StringProperty emailAddressProperty() { - return contactWrapper.field("emailAddress", Contact::getEmailAddress, Contact::setEmailAddress); + public String getTitle() { + return contact.getTitle(); } - public IntegerProperty ageProperty() { - return age; + public String getEmailAddress() { + return contact.getEmailAddress(); } - public StringProperty cityProperty() { - return contactWrapper.field("city", - (StringGetter) model -> model.getAddress().getCity(), - (model, value) -> model.getAddress().setCity(value)); + public String getCity() { + return contact.getAddress().getCity(); } - public StringProperty streetProperty() { - return contactWrapper.field("street", - (StringGetter) model -> model.getAddress().getStreet(), - (model, value) -> model.getAddress().setStreet(value)); + public String getStreet() { + return contact.getAddress().getStreet(); } - public StringProperty postalCodeProperty() { - return contactWrapper.field("postalcode", - (StringGetter) model -> model.getAddress().getPostalcode(), - (model, value) -> model.getAddress().setPostalcode(value)); + public String getPostalCode() { + return contact.getAddress().getPostalcode(); } } diff --git a/examples/contacts-example/src/main/java/de/saxsys/mvvmfx/examples/contacts/ui/master/MasterViewModel.java b/examples/contacts-example/src/main/java/de/saxsys/mvvmfx/examples/contacts/ui/master/MasterViewModel.java index ec2b77e60..1dfd4f1bf 100644 --- a/examples/contacts-example/src/main/java/de/saxsys/mvvmfx/examples/contacts/ui/master/MasterViewModel.java +++ b/examples/contacts-example/src/main/java/de/saxsys/mvvmfx/examples/contacts/ui/master/MasterViewModel.java @@ -6,6 +6,7 @@ import javax.enterprise.event.Observes; import javax.inject.Inject; +import javax.inject.Singleton; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -23,6 +24,7 @@ import javafx.collections.FXCollections; import javafx.collections.ObservableList; +@Singleton public class MasterViewModel implements ViewModel { private static final Logger LOG = LoggerFactory.getLogger(MasterViewModel.class); @@ -33,7 +35,7 @@ public class MasterViewModel implements ViewModel { private final ObjectProperty selectedTableRow = new SimpleObjectProperty<>(); - private Optional> onSelect = Optional.empty(); + private Consumer onSelect; @Inject Repository repository; @@ -72,13 +74,10 @@ private void updateContactList() { if (selectedContactId != null) { Optional selectedRow = contacts.stream() - .filter(row -> row.getId().equals(selectedContactId)).findFirst(); + .filter(row -> row.getId().equals(selectedContactId)) + .findFirst(); - if (selectedRow.isPresent()) { - onSelect.ifPresent(consumer -> consumer.accept(selectedRow.get())); - } else { - onSelect.ifPresent(consumer -> consumer.accept(null)); - } + Optional.of(onSelect).ifPresent(consumer -> consumer.accept(selectedRow.orElse(null))); } } @@ -87,7 +86,7 @@ public ObservableList getContactList() { } public void setOnSelect(Consumer consumer) { - onSelect = Optional.of(consumer); + onSelect = consumer; } public ObjectProperty selectedTableRowProperty() { diff --git a/examples/contacts-example/src/test/java/de/saxsys/mvvmfx/examples/contacts/ui/master/MasterTableViewModelTest.java b/examples/contacts-example/src/test/java/de/saxsys/mvvmfx/examples/contacts/ui/master/MasterTableViewModelTest.java index 5d09ac2b0..f74bab81a 100644 --- a/examples/contacts-example/src/test/java/de/saxsys/mvvmfx/examples/contacts/ui/master/MasterTableViewModelTest.java +++ b/examples/contacts-example/src/test/java/de/saxsys/mvvmfx/examples/contacts/ui/master/MasterTableViewModelTest.java @@ -28,7 +28,7 @@ public void testCalculationOfAge() { MasterTableViewModel tableViewModel = new MasterTableViewModel(contact); - assertThat(tableViewModel.ageProperty().get()).isEqualTo(22); + assertThat(tableViewModel.getAge()).isEqualTo(22); } } From 5b8f4f912c6978bbda0b14e54e40479a1a755a1c Mon Sep 17 00:00:00 2001 From: Manuel Mauky Date: Mon, 6 Jun 2016 18:11:16 +0200 Subject: [PATCH 06/57] fix failing test in contacts example due to previous refactoring --- .../mvvmfx/examples/contacts/ui/master/MasterViewModelTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/contacts-example/src/test/java/de/saxsys/mvvmfx/examples/contacts/ui/master/MasterViewModelTest.java b/examples/contacts-example/src/test/java/de/saxsys/mvvmfx/examples/contacts/ui/master/MasterViewModelTest.java index add9a8ca7..6ab0f089c 100644 --- a/examples/contacts-example/src/test/java/de/saxsys/mvvmfx/examples/contacts/ui/master/MasterViewModelTest.java +++ b/examples/contacts-example/src/test/java/de/saxsys/mvvmfx/examples/contacts/ui/master/MasterViewModelTest.java @@ -111,6 +111,8 @@ public void testUpdateContactListSelectionPersistsAfterUpdate() { assertThat(getContactIdsInTable()).contains(contact2.getId(), contact3.getId()) .doesNotContain(contact1.getId()); + row2 = findTableViewModelForContact(contact2); + verify(onSelectConsumer).accept(row2); } From 380d81d0df537a66c80d1e150f492e9c93b5875f Mon Sep 17 00:00:00 2001 From: Manuel Mauky Date: Mon, 6 Jun 2016 18:21:38 +0200 Subject: [PATCH 07/57] Update Links to new javadoc in Readme #392 --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index ad71a3af8..4816962fe 100644 --- a/README.md +++ b/README.md @@ -56,9 +56,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.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/) +- [javadoc mvvmfx core](http://sialcasa.github.io/mvvmFX/javadoc/1.5.0/mvvmfx/) +- [javadoc mvvmfx-cdi](http://sialcasa.github.io/mvvmFX/javadoc/1.5.0/mvvmfx-cdi/) +- [javadoc mvvmfx-guice](http://sialcasa.github.io/mvvmFX/javadoc/1.5.0/mvvmfx-guice/) +- [javadoc mvvmfx-utils](http://sialcasa.github.io/mvvmFX/javadoc/1.5.0/mvvmfx-utils/) +- [javadoc mvvmfx-testing-utils](http://sialcasa.github.io/mvvmFX/javadoc/1.5.0/mvvmfx-testing-utils/) From c8a970e13024221d7660a4f163dd9d7d2499e0b8 Mon Sep 17 00:00:00 2001 From: Manuel Mauky Date: Wed, 8 Jun 2016 16:08:21 +0200 Subject: [PATCH 08/57] Add another example for scopes that is mentioned in the Wiki doc --- .../mvvmfx/scopes/example6/Example5App.java | 25 +++++++++++ .../mvvmfx/scopes/example6/ParentView.java | 41 ++++++++++++++++++ .../scopes/example6/ParentViewModel.java | 42 +++++++++++++++++++ .../mvvmfx/scopes/example6/TabScope.java | 15 +++++++ .../mvvmfx/scopes/example6/TabView.java | 18 ++++++++ .../mvvmfx/scopes/example6/TabViewModel.java | 16 +++++++ .../mvvmfx/scopes/example6/ParentView.fxml | 24 +++++++++++ .../mvvmfx/scopes/example6/TabView.fxml | 16 +++++++ 8 files changed, 197 insertions(+) create mode 100644 mvvmfx/src/test/java/de/saxsys/mvvmfx/scopes/example6/Example5App.java create mode 100644 mvvmfx/src/test/java/de/saxsys/mvvmfx/scopes/example6/ParentView.java create mode 100644 mvvmfx/src/test/java/de/saxsys/mvvmfx/scopes/example6/ParentViewModel.java create mode 100644 mvvmfx/src/test/java/de/saxsys/mvvmfx/scopes/example6/TabScope.java create mode 100644 mvvmfx/src/test/java/de/saxsys/mvvmfx/scopes/example6/TabView.java create mode 100644 mvvmfx/src/test/java/de/saxsys/mvvmfx/scopes/example6/TabViewModel.java create mode 100644 mvvmfx/src/test/resources/de/saxsys/mvvmfx/scopes/example6/ParentView.fxml create mode 100644 mvvmfx/src/test/resources/de/saxsys/mvvmfx/scopes/example6/TabView.fxml diff --git a/mvvmfx/src/test/java/de/saxsys/mvvmfx/scopes/example6/Example5App.java b/mvvmfx/src/test/java/de/saxsys/mvvmfx/scopes/example6/Example5App.java new file mode 100644 index 000000000..9992d89af --- /dev/null +++ b/mvvmfx/src/test/java/de/saxsys/mvvmfx/scopes/example6/Example5App.java @@ -0,0 +1,25 @@ +package de.saxsys.mvvmfx.scopes.example6; + +import de.saxsys.mvvmfx.FluentViewLoader; +import javafx.application.Application; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.stage.Stage; + +public class Example5App extends Application { + + public static void main(String[] args) { + launch(args); + } + + @Override + public void start(Stage primaryStage) throws Exception { + + Parent parent = FluentViewLoader.fxmlView(ParentView.class) + .load() + .getView(); + + primaryStage.setScene(new Scene(parent)); + primaryStage.show(); + } +} diff --git a/mvvmfx/src/test/java/de/saxsys/mvvmfx/scopes/example6/ParentView.java b/mvvmfx/src/test/java/de/saxsys/mvvmfx/scopes/example6/ParentView.java new file mode 100644 index 000000000..afcb5f0e7 --- /dev/null +++ b/mvvmfx/src/test/java/de/saxsys/mvvmfx/scopes/example6/ParentView.java @@ -0,0 +1,41 @@ +package de.saxsys.mvvmfx.scopes.example6; + +import de.saxsys.mvvmfx.FluentViewLoader; +import de.saxsys.mvvmfx.FxmlView; +import de.saxsys.mvvmfx.InjectViewModel; +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.scene.Parent; +import javafx.scene.control.Tab; +import javafx.scene.control.TabPane; +import javafx.scene.control.TextField; + +public class ParentView implements FxmlView { + + @FXML + public TextField newTabContent; + @FXML + public TabPane tabPane; + + @InjectViewModel + private ParentViewModel viewModel; + + public void initialize() { + newTabContent.textProperty().bindBidirectional(viewModel.inputProperty()); + + viewModel.setNewTabAction(scopes -> { + Parent tabView = FluentViewLoader.fxmlView(TabView.class) + .providedScopes(scopes) + .load() + .getView(); + + int nextIndex = tabPane.getTabs().size(); + tabPane.getTabs().add(new Tab("Tab" + nextIndex, tabView)); + }); + + } + + public void addTab() { + viewModel.addTab(); + } +} diff --git a/mvvmfx/src/test/java/de/saxsys/mvvmfx/scopes/example6/ParentViewModel.java b/mvvmfx/src/test/java/de/saxsys/mvvmfx/scopes/example6/ParentViewModel.java new file mode 100644 index 000000000..11cecb1dd --- /dev/null +++ b/mvvmfx/src/test/java/de/saxsys/mvvmfx/scopes/example6/ParentViewModel.java @@ -0,0 +1,42 @@ +package de.saxsys.mvvmfx.scopes.example6; + +import de.saxsys.mvvmfx.Scope; +import de.saxsys.mvvmfx.ViewModel; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; + +import java.util.Collections; +import java.util.List; +import java.util.function.Consumer; + +public class ParentViewModel implements ViewModel { + + private StringProperty input = new SimpleStringProperty(); + + + private Consumer> newTabAction; + + public void addTab() { + if(newTabAction != null) { + + String value = input.getValue(); + + if (value != null && !value.trim().isEmpty()) { + + TabScope tabScope = new TabScope(); + tabScope.contentProperty().set(value); + + newTabAction.accept(Collections.singletonList(tabScope)); + input.setValue(""); + } + } + } + + public void setNewTabAction(Consumer> newTabAction) { + this.newTabAction = newTabAction; + } + + public StringProperty inputProperty() { + return input; + } +} diff --git a/mvvmfx/src/test/java/de/saxsys/mvvmfx/scopes/example6/TabScope.java b/mvvmfx/src/test/java/de/saxsys/mvvmfx/scopes/example6/TabScope.java new file mode 100644 index 000000000..b2d93475a --- /dev/null +++ b/mvvmfx/src/test/java/de/saxsys/mvvmfx/scopes/example6/TabScope.java @@ -0,0 +1,15 @@ +package de.saxsys.mvvmfx.scopes.example6; + +import de.saxsys.mvvmfx.Scope; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; + +public class TabScope implements Scope { + + private StringProperty content = new SimpleStringProperty(); + + public StringProperty contentProperty() { + return content; + } + +} diff --git a/mvvmfx/src/test/java/de/saxsys/mvvmfx/scopes/example6/TabView.java b/mvvmfx/src/test/java/de/saxsys/mvvmfx/scopes/example6/TabView.java new file mode 100644 index 000000000..fc4654499 --- /dev/null +++ b/mvvmfx/src/test/java/de/saxsys/mvvmfx/scopes/example6/TabView.java @@ -0,0 +1,18 @@ +package de.saxsys.mvvmfx.scopes.example6; + +import de.saxsys.mvvmfx.FxmlView; +import de.saxsys.mvvmfx.InjectViewModel; +import javafx.fxml.FXML; +import javafx.scene.control.Label; + +public class TabView implements FxmlView { + @FXML + public Label content; + + @InjectViewModel + private TabViewModel viewModel; + + public void initialize() { + content.textProperty().bind(viewModel.labelTextProperty()); + } +} diff --git a/mvvmfx/src/test/java/de/saxsys/mvvmfx/scopes/example6/TabViewModel.java b/mvvmfx/src/test/java/de/saxsys/mvvmfx/scopes/example6/TabViewModel.java new file mode 100644 index 000000000..f424b4dd3 --- /dev/null +++ b/mvvmfx/src/test/java/de/saxsys/mvvmfx/scopes/example6/TabViewModel.java @@ -0,0 +1,16 @@ +package de.saxsys.mvvmfx.scopes.example6; + +import de.saxsys.mvvmfx.InjectScope; +import de.saxsys.mvvmfx.ViewModel; +import javafx.beans.property.StringProperty; + +public class TabViewModel implements ViewModel { + + @InjectScope + private TabScope scope; + + public StringProperty labelTextProperty() { + return scope.contentProperty(); + } + +} diff --git a/mvvmfx/src/test/resources/de/saxsys/mvvmfx/scopes/example6/ParentView.fxml b/mvvmfx/src/test/resources/de/saxsys/mvvmfx/scopes/example6/ParentView.fxml new file mode 100644 index 000000000..03af90d78 --- /dev/null +++ b/mvvmfx/src/test/resources/de/saxsys/mvvmfx/scopes/example6/ParentView.fxml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + +