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.promodeals; import com.save.abstractclasses.AbstractDataGridProperties; import com.save.reports.PromoDealAcknowledgementReport; import com.save.service.ClientService; import com.save.service.PromoDealService; import com.save.serviceprovider.ClientServiceImpl; import com.save.serviceprovider.PromoDealServiceImpl; import com.save.utilities.CommonUtilities; import com.template.save.FontIconRenderer; import com.vaadin.data.Item; import com.vaadin.ui.Button; import com.vaadin.ui.UI; import com.vaadin.ui.VerticalLayout; import com.vaadin.ui.Window; import com.vaadin.ui.themes.ValoTheme; import com.save.clients.AcknowledgementPromoForm; /** * * @author jetdario */ public class PDDataGridProperties extends AbstractDataGridProperties { ClientService cs = new ClientServiceImpl(); PromoDealService pds = new PromoDealServiceImpl(); private int clientId; public PDDataGridProperties(int clientId) { this.clientId = clientId; setWidth("100%"); setHeight("100%"); setContainerDataSource(new PDDataContainer(getClientId())); gridRenrderersAndGenerator(); } @Override public void populateDataGrid() { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void gridRenrderersAndGenerator() { getColumn("view").setWidth(40); getColumn("edit").setWidth(40); getColumn("del").setWidth(40); getDefaultHeaderRow().join("view", "edit", "del").setText(""); setFrozenColumnCount(1); getColumn("del").setRenderer(new FontIconRenderer(e -> { Object itemId = e.getItemId(); Item item = getContainerDataSource().getItem(itemId); Window sub = delete(itemId, CommonUtilities.convertStringToInt(item.getItemProperty("sn").getValue().toString())); if (sub.getParent() == null) { UI.getCurrent().addWindow(sub); } })); getColumn("edit").setRenderer(new FontIconRenderer(e -> { Object itemId = e.getItemId(); Item item = getContainerDataSource().getItem(itemId); Window sub = new AcknowledgementPromoForm(getClientId(), (int) item.getItemProperty("sn").getValue()); if (sub.getParent() == null) { UI.getCurrent().addWindow(sub); } sub.addCloseListener((Window.CloseEvent event) -> { getContainerDataSource().removeAllItems(); setContainerDataSource(new PDDataContainer(getClientId())); }); })); getColumn("view").setRenderer(new FontIconRenderer(e -> { Object itemId = e.getItemId(); Item item = getContainerDataSource().getItem(itemId); Window sub = new PromoDealAcknowledgementReport( CommonUtilities.convertStringToInt(item.getItemProperty("sn").getValue().toString())); if (sub.getParent() == null) { UI.getCurrent().addWindow(sub); } })); recalculateColumnWidths(); } int getClientId() { return clientId; } Window delete(Object itemId, int promoId) { Window sub = new Window("REMOVE PROMO DEAL"); sub.setWidth("250px"); sub.setModal(true); sub.center(); VerticalLayout v = new VerticalLayout(); v.setWidth("100%"); v.setMargin(true); Button delBtn = new Button("CONFIRM DELETE?", (Button.ClickEvent event) -> { boolean result = pds.delete(promoId, "removed"); getContainerDataSource().removeItem(itemId); sub.close(); }); delBtn.setWidth("100%"); delBtn.addStyleName(ValoTheme.BUTTON_PRIMARY); delBtn.addStyleName(ValoTheme.BUTTON_SMALL); v.addComponent(delBtn); sub.setContent(v); return sub; } }