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.vaadin.ui.Button; import com.vaadin.ui.HorizontalSplitPanel; import com.vaadin.ui.Label; import com.vaadin.ui.Notification; import com.vaadin.ui.TextArea; import com.vaadin.ui.UI; import com.vaadin.ui.VerticalLayout; import com.vaadin.ui.Window; /** * * @author jetdario */ public class RemoveAccountWindow extends Window { ClientService clientService = new ClientServiceImpl(); private int clientId; public RemoveAccountWindow(int clientId) { this.clientId = clientId; setCaption("REMOVE ACCOUNT"); setWidth("250px"); setModal(true); setResizable(false); center(); setContent(getVLayout()); getContent().setHeightUndefined(); } VerticalLayout getVLayout() { VerticalLayout vlayout = new VerticalLayout(); vlayout.setSpacing(true); vlayout.setMargin(true); vlayout.setSizeFull(); final TextArea remarks = new TextArea("Remarks: "); remarks.setRows(2); remarks.setWidth("100%"); vlayout.addComponent(remarks); Button removeBtn = new Button("REMOVE ACCOUNT?"); removeBtn.setWidth("100%"); removeBtn.addClickListener((Button.ClickEvent event) -> { if (remarks.getValue() == null || remarks.getValue().trim().isEmpty()) { Notification.show("Add Remarks!", Notification.Type.ERROR_MESSAGE); return; } boolean result = clientService.removeAccount(getClientId(), remarks.getValue().trim().toLowerCase()); if (result) { close(); } }); vlayout.addComponent(removeBtn); return vlayout; } int getClientId() { return clientId; } void getConfirmationWindow(final String str) { final Window sub = new Window("Conifrm?"); sub.setWidth("180px"); sub.setHeight("150px"); sub.center(); sub.setResizable(false); UI.getCurrent().addWindow(sub); VerticalLayout vlayout = new VerticalLayout(); vlayout.setMargin(true); vlayout.setSpacing(true); vlayout.addComponent(new Label("Client is a Distributor!")); Button removeBtn = new Button("REMOVE"); removeBtn.setWidth("100%"); removeBtn.addClickListener((Button.ClickEvent event) -> { boolean result = clientService.removeAccount(getClientId(), str); if (result) { sub.close(); close(); } }); vlayout.addComponent(removeBtn); sub.setContent(vlayout); sub.addCloseListener((CloseEvent e) -> { close(); }); } }