From 3773c5211ef7eebe1976885fbbe391097306acd3 Mon Sep 17 00:00:00 2001 From: Igor Baiborodine Date: Fri, 1 Jan 2016 18:46:24 -0500 Subject: [PATCH] Misc fixes --- .../ui/component/CartItemListTable.java | 11 +++++-- .../ui/component/ItemListTable.java | 11 +++++-- .../vaadinspring/ui/view/CartView.java | 8 ++--- .../vaadinspring/ui/view/ItemListView.java | 6 ++-- .../vaadinspring/ui/view/SearchView.java | 29 +++++++++++++++---- 5 files changed, 49 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/kiroule/jpetstore/vaadinspring/ui/component/CartItemListTable.java b/src/main/java/com/kiroule/jpetstore/vaadinspring/ui/component/CartItemListTable.java index 6602cc0..08e37b7 100644 --- a/src/main/java/com/kiroule/jpetstore/vaadinspring/ui/component/CartItemListTable.java +++ b/src/main/java/com/kiroule/jpetstore/vaadinspring/ui/component/CartItemListTable.java @@ -22,6 +22,8 @@ import java.math.BigDecimal; +import static java.lang.String.format; + /** * @author Igor Baiborodine */ @@ -97,8 +99,13 @@ private void viewDetails(Button.ClickEvent event) { if (isReadOnly()) { productItemForm.getAddToCartButton().setEnabled(false); } - productItemForm.setEntity((Item) event.getButton().getData()); - productItemForm.openInModalPopup().setCaption("View Details"); + Item item = (Item) event.getButton().getData(); + productItemForm.setEntity(item); + productItemForm.openInModalPopup().setCaption(getPopupCaption(item)); + } + + private String getPopupCaption(Item item) { + return format("%s | %s", item.getProductId(), item.getProduct().getName()); } private String convertToCurrencyPresentation(BigDecimal value) { diff --git a/src/main/java/com/kiroule/jpetstore/vaadinspring/ui/component/ItemListTable.java b/src/main/java/com/kiroule/jpetstore/vaadinspring/ui/component/ItemListTable.java index 8356690..ca8afc6 100644 --- a/src/main/java/com/kiroule/jpetstore/vaadinspring/ui/component/ItemListTable.java +++ b/src/main/java/com/kiroule/jpetstore/vaadinspring/ui/component/ItemListTable.java @@ -14,6 +14,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.vaadin.viritin.fields.MTable; +import static java.lang.String.format; + /** * @author Igor Baiborodine */ @@ -48,7 +50,12 @@ public ItemListTable() { } private void viewDetails(Button.ClickEvent event) { - productItemForm.setEntity((Item) event.getButton().getData()); - productItemForm.openInModalPopup().setCaption("View Details"); + Item item = (Item) event.getButton().getData(); + productItemForm.setEntity(item); + productItemForm.openInModalPopup().setCaption(getPopupCaption(item)); + } + + private String getPopupCaption(Item item) { + return format("%s | %s", item.getProductId(), item.getProduct().getName()); } } \ No newline at end of file diff --git a/src/main/java/com/kiroule/jpetstore/vaadinspring/ui/view/CartView.java b/src/main/java/com/kiroule/jpetstore/vaadinspring/ui/view/CartView.java index bf33534..21d11d7 100644 --- a/src/main/java/com/kiroule/jpetstore/vaadinspring/ui/view/CartView.java +++ b/src/main/java/com/kiroule/jpetstore/vaadinspring/ui/view/CartView.java @@ -1,8 +1,5 @@ package com.kiroule.jpetstore.vaadinspring.ui.view; -import static com.kiroule.jpetstore.vaadinspring.ui.util.CurrentCart.Key.SHOPPING_CART; -import static java.lang.String.format; - import com.kiroule.jpetstore.vaadinspring.domain.Cart; import com.kiroule.jpetstore.vaadinspring.ui.component.CartItemListTable; import com.kiroule.jpetstore.vaadinspring.ui.converter.CurrencyConverter; @@ -27,6 +24,9 @@ import javax.annotation.PostConstruct; +import static com.kiroule.jpetstore.vaadinspring.ui.util.CurrentCart.Key.SHOPPING_CART; +import static java.lang.String.format; + /** * @author Igor Baiborodine */ @@ -83,7 +83,7 @@ public void executeOnEnter(ViewChangeListener.ViewChangeEvent event) { } private Label initEmptyCartLabel() { - emptyCartLabel = new Label("Your Shopping Cart is empty."); + emptyCartLabel = new Label("Your shopping cart is empty."); emptyCartLabel.setStyleName(JPetStoreTheme.VIEW_LABEL_MEDIUM); return emptyCartLabel; } diff --git a/src/main/java/com/kiroule/jpetstore/vaadinspring/ui/view/ItemListView.java b/src/main/java/com/kiroule/jpetstore/vaadinspring/ui/view/ItemListView.java index b382a0d..15575af 100644 --- a/src/main/java/com/kiroule/jpetstore/vaadinspring/ui/view/ItemListView.java +++ b/src/main/java/com/kiroule/jpetstore/vaadinspring/ui/view/ItemListView.java @@ -1,7 +1,5 @@ package com.kiroule.jpetstore.vaadinspring.ui.view; -import static java.lang.String.format; - import com.kiroule.jpetstore.vaadinspring.domain.Product; import com.kiroule.jpetstore.vaadinspring.service.CatalogService; import com.kiroule.jpetstore.vaadinspring.ui.component.ItemListTable; @@ -13,6 +11,8 @@ import javax.annotation.PostConstruct; +import static java.lang.String.format; + /** * @author Igor Baiborodine */ @@ -46,6 +46,6 @@ public void executeOnEnter(ViewChangeListener.ViewChangeEvent event) { @Override public String getTitleLabelValue() { - return format("%s | %s", product.getName(), product.getProductId()); + return format("%s | %s", product.getProductId(), product.getName()); } } \ No newline at end of file diff --git a/src/main/java/com/kiroule/jpetstore/vaadinspring/ui/view/SearchView.java b/src/main/java/com/kiroule/jpetstore/vaadinspring/ui/view/SearchView.java index 28be173..3fa7f1e 100644 --- a/src/main/java/com/kiroule/jpetstore/vaadinspring/ui/view/SearchView.java +++ b/src/main/java/com/kiroule/jpetstore/vaadinspring/ui/view/SearchView.java @@ -1,18 +1,23 @@ package com.kiroule.jpetstore.vaadinspring.ui.view; -import static java.lang.String.format; - +import com.kiroule.jpetstore.vaadinspring.domain.Product; import com.kiroule.jpetstore.vaadinspring.service.CatalogService; import com.kiroule.jpetstore.vaadinspring.ui.component.ProductListTable; +import com.kiroule.jpetstore.vaadinspring.ui.theme.JPetStoreTheme; import com.kiroule.jpetstore.vaadinspring.ui.util.ViewConfig; import com.kiroule.jpetstore.vaadinspring.ui.util.ViewConfigUtil; import com.vaadin.navigator.ViewChangeListener; import com.vaadin.spring.annotation.SpringView; +import com.vaadin.ui.Label; import org.springframework.beans.factory.annotation.Autowired; +import java.util.List; + import javax.annotation.PostConstruct; +import static java.lang.String.format; + /** * @author Igor Baiborodine */ @@ -29,23 +34,37 @@ public class SearchView extends AbstractView { @Autowired private ProductListTable productListTable; + private Label noResultLabel; private String keyword; + private String noResultMessage = "Your search \"%s\" did not match any products."; @PostConstruct public void init() { - addComponents(initTitleLabel(), productListTable); + addComponents(initTitleLabel(), initNoResultLabel(), productListTable); setSizeFull(); - expand(productListTable); } @Override public void executeOnEnter(ViewChangeListener.ViewChangeEvent event) { + keyword = event.getParameters(); - productListTable.setBeans(catalogService.searchProductList(keyword)); + List products = catalogService.searchProductList(keyword); + noResultLabel.setValue(format(noResultMessage, keyword)); + noResultLabel.setVisible(products.isEmpty()); + + productListTable.setBeans(products); + productListTable.setVisible(!products.isEmpty()); + expand(products.isEmpty() ? noResultLabel : productListTable); } @Override public String getTitleLabelValue() { return format("%s | %s", ViewConfigUtil.getDisplayName(this.getClass()), keyword); } + + private Label initNoResultLabel() { + noResultLabel = new Label(noResultMessage); + noResultLabel.setStyleName(JPetStoreTheme.VIEW_LABEL_MEDIUM); + return noResultLabel; + } } \ No newline at end of file