com.save.employee.maintenance.MRUI.java Source code

Java tutorial

Introduction

Here is the source code for com.save.employee.maintenance.MRUI.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.maintenance;

import com.vaadin.server.FontAwesome;
import com.vaadin.shared.ui.MarginInfo;
import com.vaadin.ui.Button;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.UI;
import com.vaadin.ui.Window;
import com.vaadin.ui.themes.ValoTheme;

/**
 *
 * @author jetdario
 */
public class MRUI extends VerticalLayout {

    private int employeeId;

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

        setWidth("90%");
        setHeight("100%");
        setMargin(new MarginInfo(true, false, false, false));

        MRDataGridProperties dataGrid = new MRDataGridProperties(getEmployeeId());

        Button mrForm = new Button("Maintenance/Reimbursement Form");
        mrForm.setWidthUndefined();
        mrForm.setIcon(FontAwesome.OPENID);
        mrForm.addStyleName(ValoTheme.BUTTON_SMALL);
        mrForm.addStyleName(ValoTheme.BUTTON_LINK);
        mrForm.addClickListener((Button.ClickEvent event) -> {
            Window sub = new MRFormWindow(getEmployeeId());
            if (sub.getParent() == null) {
                UI.getCurrent().addWindow(sub);
            }

            sub.addCloseListener((Window.CloseEvent e) -> {
                dataGrid.getContainerDataSource().removeAllItems();
                dataGrid.setContainerDataSource(new MRDataContainer(getEmployeeId()));
            });
        });

        addComponent(mrForm);
        setComponentAlignment(mrForm, Alignment.MIDDLE_RIGHT);

        addComponent(dataGrid);
        setExpandRatio(dataGrid, 2);
    }

    int getEmployeeId() {
        return employeeId;
    }
}