Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.save.client; import com.save.service.ClientService; import com.save.serviceprovider.ClientServiceImpl; import com.save.utilities.CommonUtilities; import com.vaadin.data.Item; import com.vaadin.event.ItemClickEvent; import com.vaadin.ui.Panel; import com.vaadin.ui.Table; import com.vaadin.ui.UI; import com.vaadin.ui.Window; import java.util.List; /** * * @author jetdario */ public class PromoDeals extends Panel implements ItemClickEvent.ItemClickListener, Window.CloseListener { ClientService cs = new ClientServiceImpl(); Table table = new Table(); private int clientId; public PromoDeals(int clientId) { this.clientId = clientId; setCaption("Promo Deals"); setSizeFull(); initializeTable(); setContent(generateTableData()); } void initializeTable() { table.setSizeFull(); table.setSelectable(true); table.addStyleName("compact"); table.setImmediate(true); table.addContainerProperty("SN", Integer.class, null); table.addContainerProperty("PROMO ITEMS", String.class, null); table.addContainerProperty("AMOUNT", Double.class, null); table.addContainerProperty("QUANTITY", Double.class, null); table.addContainerProperty("PRODUCT", String.class, null); table.setColumnWidth("SN", 50); table.setColumnWidth("AMOUNT", 100); table.setColumnWidth("QUANTITY", 100); } public Table generateTableData() { table.removeAllItems(); // List<PromoDeals> listPromoDeals = cs.getPromoDealsByClientId(getClientId()); // int i = 0; // for (PromoDeals promoDealsBean : listPromoDeals) { // table.addItem(new Object[]{ // promoDealsBean.getPromoId(), // promoDealsBean.getPromoItem(), // promoDealsBean.getPromoAmount(), // promoDealsBean.getQuantity(), // promoDealsBean.getProductItem() // }, new Integer(i)); // i++; // } // table.setPageLength(0); // table.addItemClickListener(this); return table; } @Override public void itemClick(ItemClickEvent event) { //TO DO Object itemId = event.getItemId(); Item item = table.getItem(itemId); // Window sub = new DeletePromoWindow(CommonUtilities.convertStringToInt(item.getItemProperty("SN").getValue().toString())); // UI.getCurrent().addWindow(sub); // sub.addCloseListener(this); } int getClientId() { return clientId; } @Override public void windowClose(Window.CloseEvent e) { setContent(generateTableData()); } }