Skip to content

Commit

Permalink
Add checkout logic in ShoppingCartView
Browse files Browse the repository at this point in the history
  • Loading branch information
amahdy committed Dec 23, 2015
1 parent 1208a7e commit f37a382
Showing 1 changed file with 33 additions and 4 deletions.
Expand Up @@ -22,6 +22,9 @@
import com.vaadin.ui.Label;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;
import com.vaadin.ui.Window.CloseEvent;
import com.vaadin.ui.Window.CloseListener;
import com.vaadin.ui.themes.ValoTheme;

@UIScoped
Expand Down Expand Up @@ -80,7 +83,6 @@ protected String getViewHeader() {
@Override
protected void createControllerButtons() {
createButton(checkoutButton, "Checkout", VaadinIcons.FLAG_CHECKERED);
checkoutButton.setEnabled(false);
checkoutButton.addStyleName(ValoTheme.BUTTON_PRIMARY);

createButton(clearButton, "Clear", VaadinIcons.CLOSE);
Expand Down Expand Up @@ -128,6 +130,10 @@ private void updateDatasource() {

if (sc.getShoppingCartItemList().size() > 0) {
shoppingCartService.priceShoppingCart(sc);

checkoutButton.setEnabled(true);
} else {
checkoutButton.setEnabled(false);
}

// BUG #4302 - Can not update the bean in BeanItem
Expand All @@ -138,6 +144,11 @@ public void updateShoppingCart(@Observes UpdateShopppingCartEvent event) {
updateDatasource();
}

private void clear() {
resetShoppingCart();
updateDatasource();
}

private void clearShoppingCart() {
ConfirmDialog dialog = ConfirmDialog.show(UI.getCurrent(),
"Confirm Clearing Shopping Cart",
Expand All @@ -153,8 +164,7 @@ private void clearShoppingCart() {
public void onClose(ConfirmDialog dialog) {
if (dialog.isConfirmed()) {
// Confirmed to clear
resetShoppingCart();
updateDatasource();
clear();
}
}
});
Expand All @@ -163,12 +173,31 @@ public void onClose(ConfirmDialog dialog) {
dialog.getCancelButton().addStyleName(ValoTheme.BUTTON_LINK);
}

private void checkout() {
Window checkout = new Window("Thank you for your order!");
checkout.setResizable(false);
checkout.setSizeFull();
checkout.addCloseListener(new CloseListener() {

/**
*
*/
private static final long serialVersionUID = -6352682494377073401L;

@Override
public void windowClose(CloseEvent e) {
clear();
}
});
UI.getCurrent().addWindow(checkout);
}

@Override
public void buttonClick(ClickEvent event) {
if (event.getButton() == getClearButton()) {
clearShoppingCart();
} else if (event.getButton() == getCheckoutButton()) {
updateDatasource();
checkout();
}
}
}

0 comments on commit f37a382

Please sign in to comment.