com.save.employee.RemoveAccountWindow.java Source code

Java tutorial

Introduction

Here is the source code for com.save.employee.RemoveAccountWindow.java

Source

/*
 * 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;

import com.save.service.EmployeeService;
import com.save.employee.serviceprovider.EmployeeServiceImpl;
import com.vaadin.ui.Button;
import com.vaadin.ui.Grid;
import com.vaadin.ui.Notification;
import com.vaadin.ui.TextArea;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;

/**
 *
 * @author jetdario
 */
public class RemoveAccountWindow extends Window {

    EmployeeService employeeService = new EmployeeServiceImpl();
    private int employeeId;

    public RemoveAccountWindow(int employeeId) {
        this.employeeId = employeeId;

        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 = employeeService.removeAccount(getEmployeeId(),
                    remarks.getValue().trim().toLowerCase());
            if (result) {
                close();
            }
        });
        vlayout.addComponent(removeBtn);

        return vlayout;
    }

    int getEmployeeId() {
        return employeeId;
    }
}