Skip to content
This repository has been archived by the owner on Dec 7, 2019. It is now read-only.

Commit

Permalink
Misc fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Baiborodine committed Jan 1, 2016
1 parent 4630fb3 commit 3773c52
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

import java.math.BigDecimal;

import static java.lang.String.format;

/**
* @author Igor Baiborodine
*/
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
*/
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -13,6 +11,8 @@

import javax.annotation.PostConstruct;

import static java.lang.String.format;

/**
* @author Igor Baiborodine
*/
Expand Down Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -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
*/
Expand All @@ -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<Product> 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;
}
}

0 comments on commit 3773c52

Please sign in to comment.