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.employee.request; import com.save.abstractclasses.AbstractDataGridProperties; import com.save.global.ErrorLoggedNotification; import com.save.service.RLService; import com.save.employee.serviceprovider.RLServiceImpl; import com.save.utilities.CommonUtilities; import com.template.save.FontIconRenderer; import com.vaadin.data.Item; import com.vaadin.shared.ui.label.ContentMode; import com.vaadin.ui.Button; import com.vaadin.ui.Label; import com.vaadin.ui.Notification; import com.vaadin.ui.UI; import com.vaadin.ui.VerticalLayout; import com.vaadin.ui.Window; import com.vaadin.ui.themes.ValoTheme; /** * * @author jetdario */ public class RLDataGridProperties extends AbstractDataGridProperties { RLService rls = new RLServiceImpl(); private int employeeId; public RLDataGridProperties(int employeeId) { this.employeeId = employeeId; setWidth("100%"); setHeight("100%"); setContainerDataSource(new RLDataContainer(getEmployeeId())); gridRenrderersAndGenerator(); } @Override public void populateDataGrid() { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void gridRenrderersAndGenerator() { //TODO removeColumn("id"); getDefaultHeaderRow().join("edit", "liquidate", "view", "del").setText(""); setFrozenColumnCount(1); getColumn("del").setRenderer(new FontIconRenderer(e -> { Object itemId = e.getItemId(); Item item = getContainerDataSource().getItem(itemId); int result = rls .getRLById(CommonUtilities.convertStringToInt(item.getItemProperty("id").getValue().toString())) .getLiquidated(); if (result == 1) { // Notification.show(label.getCaption(), Notification.Type.WARNING_MESSAGE); ErrorLoggedNotification.showWarningLoggedOnWindow( "Your are not allowed to delete a reguest that has already been liquidated!", this.getClass().getName()); return; } Window sub = deletConfirmationWindow( CommonUtilities.convertStringToInt(item.getItemProperty("id").getValue().toString()), itemId); if (sub.getParent() == null) { UI.getCurrent().addWindow(sub); } })); getColumn("liquidate").setRenderer(new FontIconRenderer(e -> { Object itemId = e.getItemId(); Item item = getContainerDataSource().getItem(itemId); int result = rls .getRLById(CommonUtilities.convertStringToInt(item.getItemProperty("id").getValue().toString())) .getLiquidated(); if (result == 1) { Notification.show("Request has already been Liquidated. Click View instead!", Notification.Type.WARNING_MESSAGE); return; } Window sub = new RequestFormWindow(getEmployeeId(), CommonUtilities.convertStringToInt(item.getItemProperty("id").getValue().toString()), true, this); if (sub.getParent() == null) { UI.getCurrent().addWindow(sub); } })); getColumn("view").setRenderer(new FontIconRenderer(e -> { Object itemId = e.getItemId(); Item item = getContainerDataSource().getItem(itemId); Window sub = new ViewRLWindow(getEmployeeId(), CommonUtilities.convertStringToInt(item.getItemProperty("id").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); int result = rls .getRLById(CommonUtilities.convertStringToInt(item.getItemProperty("id").getValue().toString())) .getLiquidated(); if (result == 1) { Notification.show("Request has already been Liquidated. Click View instead!", Notification.Type.WARNING_MESSAGE); return; } Window sub = new RequestFormWindow(getEmployeeId(), CommonUtilities.convertStringToInt(item.getItemProperty("id").getValue().toString()), false, this); if (sub.getParent() == null) { UI.getCurrent().addWindow(sub); } })); recalculateColumnWidths(); } int getEmployeeId() { return employeeId; } Window deletConfirmationWindow(int rlId, Object itemId) { Window sub = new Window(); sub.setCaption("CONFIRM DELETE"); sub.setWidth("250px"); sub.setModal(true); VerticalLayout v = new VerticalLayout(); v.setWidth("100%"); v.setMargin(true); Button deleteBtn = new Button("DELETE?"); deleteBtn.setWidth("100%"); deleteBtn.addStyleName(ValoTheme.BUTTON_PRIMARY); deleteBtn.addClickListener((Button.ClickEvent event) -> { boolean result = rls.deleteRequestById(rlId); if (result) { getContainerDataSource().removeItem(itemId); sub.close(); } }); v.addComponent(deleteBtn); sub.setContent(v); sub.getContent().setHeightUndefined(); return sub; } }