task: MVVM design pattern using zkoss framework. (#1678)

* MVVM design pattern using zkoss framework.

* MVVM Design pattern updates for issues reported by SonarCloud.

* MVVM Design pattern updates for coverage issues reported by SonarCloud.

* MVVM Design pattern updates for coverage issues (removing lombok @Data)
reported by SonarCloud.

* MVVM Design pattern updates for coverage issues reported by Sonar - TEST
cases added for Equals and ToString

* MVVM Design Pattern - updating missing/todo details.

* MVVM Design Pattern - adding lombok.config

* MVVM Design Pattern - Removing xml, updating pom.xml and README as per
suggested changes in code review

* Update model-view-viewmodel/README.md

* Update model-view-viewmodel/README.md

* Update model-view-viewmodel/README.md

* Update model-view-viewmodel/README.md

* MVVM Design Pattern - Updated pom.xml and Readme based on Suggested
changes

* added type as xml

* MVVM Design Patterm - root pom.xml and module pom.xml updated

* Update pom.xml

Co-authored-by: Subhrodip Mohanta <hello@subho.xyz>
Co-authored-by: Ilkka Seppälä <iluwatar@users.noreply.github.com>
This commit is contained in:
jinishavora
2021-03-22 02:13:34 -04:00
committed by GitHub
parent 2b7d181ac4
commit 794795acf5
15 changed files with 730 additions and 2 deletions
@@ -0,0 +1,37 @@
/*
* The MIT License
* Copyright © 2014-2021 Ilkka Seppälä
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.model.view.viewmodel;
import lombok.AllArgsConstructor;
import lombok.Data;
@AllArgsConstructor
@Data
public class Book {
private String name;
private String author;
private String description;
}
@@ -0,0 +1,10 @@
package com.iluwatar.model.view.viewmodel;
import java.util.List;
public interface BookService {
/* List all books
* @return all books
*/
public List<Book> load();
}
@@ -0,0 +1,38 @@
package com.iluwatar.model.view.viewmodel;
import java.util.ArrayList;
import java.util.List;
public class BookServiceImpl implements BookService {
private List<Book> designPatternBooks = new ArrayList<>();
/** Initializes Book Data.
* To be used and passed along in load method
* In this case, list design pattern books are initialized to be loaded.
*/
public BookServiceImpl() {
designPatternBooks.add(new Book(
"Head First Design Patterns: A Brain-Friendly Guide",
"Eric Freeman, Bert Bates, Kathy Sierra, Elisabeth Robson",
"Head First Design Patterns Description"));
designPatternBooks.add(new Book(
"Design Patterns: Elements of Reusable Object-Oriented Software",
"Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides",
"Design Patterns Description"));
designPatternBooks.add(new Book(
"Patterns of Enterprise Application Architecture", "Martin Fowler",
"Patterns of Enterprise Application Architecture Description"));
designPatternBooks.add(new Book(
"Design Patterns Explained", "Alan Shalloway, James Trott",
"Design Patterns Explained Description"));
designPatternBooks.add(new Book(
"Applying UML and Patterns: An Introduction to "
+ "Object-Oriented Analysis and Design and Iterative Development",
"Craig Larman", "Applying UML and Patterns Description"));
}
public List<Book> load() {
return designPatternBooks;
}
}
@@ -0,0 +1,43 @@
package com.iluwatar.model.view.viewmodel;
import java.util.List;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.NotifyChange;
import org.zkoss.zk.ui.select.annotation.WireVariable;
public class BookViewModel {
@WireVariable
private List<Book> bookList;
private Book selectedBook;
private BookService bookService = new BookServiceImpl();
public Book getSelectedBook() {
return selectedBook;
}
@NotifyChange("selectedBook")
public void setSelectedBook(Book selectedBook) {
this.selectedBook = selectedBook;
}
public List<Book> getBookList() {
return bookService.load();
}
/** Deleting a book.
* When event is triggered on click of Delete button,
* this method will be notified with the selected entry that will be referenced
* and used to delete the selected book from the list of books.
*/
@Command
@NotifyChange({"selectedBook","bookList"})
public void deleteBook() {
if (selectedBook != null) {
getBookList().remove(selectedBook);
selectedBook = null;
}
}
}