com.anphat.list.ui.DialogCreateDepartment.java Source code

Java tutorial

Introduction

Here is the source code for com.anphat.list.ui.DialogCreateDepartment.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.anphat.list.ui;

import com.vaadin.annotations.AutoGenerated;
import com.vaadin.data.validator.EmailValidator;
import com.vaadin.data.validator.RegexpValidator;
import com.vaadin.server.ThemeResource;
import com.vaadin.shared.ui.combobox.FilteringMode;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.TextArea;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;
import com.cms.dto.DepartmentDTO;
import com.cms.utils.BundleUtils;
import com.cms.utils.MakeURL;

/**
 *
 * @author NgocND6
 */
public class DialogCreateDepartment extends Window {

    @AutoGenerated
    private VerticalLayout mainLayout;
    @AutoGenerated
    private HorizontalLayout horizontalLayoutButton;
    @AutoGenerated
    private Button btnSave;
    @AutoGenerated
    private Button btnCancel;
    @AutoGenerated
    private GridLayout gridLayoutDepartInfo;
    //    @AutoGenerated
    //    private TextField txtContact;
    //    @AutoGenerated
    //    private Label lblContact;
    @AutoGenerated
    private TextField txtAddress;
    @AutoGenerated
    private Label lblAddress;
    @AutoGenerated
    private TextField txtEmail;
    @AutoGenerated
    private Label lblEmail;
    //    @AutoGenerated
    //    private TextField txtFax;
    //    @AutoGenerated
    //    private Label lblFax;
    @AutoGenerated
    private TextField txtPhoneNumber;
    @AutoGenerated
    private Label lblPhoneNumber;
    @AutoGenerated
    private ComboBox cbxStatus;
    @AutoGenerated
    private Label lblStatus;
    @AutoGenerated
    private TextArea textArea_1;
    @AutoGenerated
    private Label lblDescription;
    //    @AutoGenerated
    //    private TextField txtSuperiorUnit;
    //    @AutoGenerated
    //    private Label lblSuperiorUnit;
    @AutoGenerated
    private TextField txtDepartmentName;
    @AutoGenerated
    private Label lblDepartmentName;
    @AutoGenerated
    private TextField txtDepartmentCode;
    @AutoGenerated
    private Label lblDepartmentCode;
    DepartmentDTO departmentDTO;
    //    private MappingCombobox comboDeptTopLevel;

    /**
     * The constructor should first build the main layout, set the composition
     * root and then do any custom initialization.
     *
     * The constructor will not be automatically regenerated by the visual
     * editor.
     */
    public DialogCreateDepartment(String captionPanel, DepartmentDTO departmentDTO) {
        this.departmentDTO = departmentDTO;
        buildMainLayout();
        setContent(mainLayout);
        setWidth("800px");
        setHeight("-1px");
        setModal(true);
        setImmediate(true);
        setCaption(captionPanel);
        // TODO add user code here
    }

    @AutoGenerated
    private VerticalLayout buildMainLayout() {
        // common part: create layout
        mainLayout = new VerticalLayout();
        mainLayout.setImmediate(true);
        mainLayout.setWidth("100%");
        mainLayout.setHeight("-1px");
        mainLayout.setMargin(true);
        mainLayout.setSpacing(true);
        setModal(true);

        // top-level component properties
        setWidth("800px");
        setHeight("-1px");

        // gridLayoutDepartInfo
        gridLayoutDepartInfo = buildGridLayoutDepartInfo();
        mainLayout.addComponent(gridLayoutDepartInfo);

        // horizontalLayoutButton
        horizontalLayoutButton = buildHorizontalLayoutButton();
        mainLayout.addComponent(horizontalLayoutButton);

        return mainLayout;
    }

    @AutoGenerated
    private GridLayout buildGridLayoutDepartInfo() {
        // common part: create layout
        gridLayoutDepartInfo = new GridLayout();
        gridLayoutDepartInfo.setStyleName("custom-feildset");
        gridLayoutDepartInfo
                .setCaption(MakeURL.makeURLForGrid(BundleUtils.getString("department.fieldset.title.deptInfo")));
        gridLayoutDepartInfo.setCaptionAsHtml(true);
        gridLayoutDepartInfo.setImmediate(true);
        gridLayoutDepartInfo.setWidth("100.0%");
        gridLayoutDepartInfo.setHeight("-1px");
        gridLayoutDepartInfo.setMargin(true);
        gridLayoutDepartInfo.setSpacing(true);
        gridLayoutDepartInfo.setColumns(4);
        gridLayoutDepartInfo.setRows(7);

        // lblDepartmentCode
        lblDepartmentCode = new Label();
        lblDepartmentCode.setImmediate(true);
        lblDepartmentCode.setWidth("100.0%");
        lblDepartmentCode.setHeight("-1px");
        lblDepartmentCode.setValue(BundleUtils.getString("lb.deptstaff.dept.code"));
        gridLayoutDepartInfo.addComponent(lblDepartmentCode, 0, 0);

        // txtDepartmentCode
        txtDepartmentCode = new TextField();
        txtDepartmentCode.setImmediate(true);
        txtDepartmentCode.setWidth("100.0%");
        txtDepartmentCode.setHeight("-1px");
        txtDepartmentCode.setMaxLength(50);
        txtDepartmentCode.setRequired(true);
        txtDepartmentCode.addValidator(
                new RegexpValidator("^[a-zA-Z0-9-_]+$", BundleUtils.getString("lb.deptstaff.dept.code") + " "
                        + BundleUtils.getString("message.error.code.format")));
        gridLayoutDepartInfo.addComponent(txtDepartmentCode, 1, 0);

        // lblDepartmentName
        lblDepartmentName = new Label();
        lblDepartmentName.setImmediate(true);
        lblDepartmentName.setWidth("100.0%");
        lblDepartmentName.setHeight("-1px");
        lblDepartmentName.setValue(BundleUtils.getString("lb.deptstaff.dept.name"));
        gridLayoutDepartInfo.addComponent(lblDepartmentName, 2, 0);

        // txtDepartmentName
        txtDepartmentName = new TextField();
        txtDepartmentName.setImmediate(true);
        txtDepartmentName.setWidth("100.0%");
        txtDepartmentName.setHeight("-1px");
        txtDepartmentName.setMaxLength(100);
        txtDepartmentName.setRequired(true);
        gridLayoutDepartInfo.addComponent(txtDepartmentName, 3, 0);

        // lblSuperiorUnit
        //        lblSuperiorUnit = new Label();
        //        lblSuperiorUnit.setImmediate(true);
        //        lblSuperiorUnit.setWidth("100.0%");
        //        lblSuperiorUnit.setHeight("-1px");
        //        lblSuperiorUnit.setValue(BundleUtils.getString("lb.deptstaff.dept.level"));
        //        gridLayoutDepartInfo.addComponent(lblSuperiorUnit, 0, 1);

        // txtSuperiorUnit
        //        txtSuperiorUnit = new TextField();
        //        txtSuperiorUnit.setImmediate(true);
        //        txtSuperiorUnit.setWidth("100.0%");
        //        txtSuperiorUnit.setHeight("-1px");
        //        comboDeptTopLevel = new MappingCombobox(3, 1);
        //        comboDeptTopLevel.getNameCombo().setRequired(true);
        //        gridLayoutDepartInfo.addComponent(comboDeptTopLevel.getLayout(), 1, 1, 3, 1);

        // lblDescription
        lblDescription = new Label();
        lblDescription.setImmediate(true);
        lblDescription.setWidth("100.0%");
        lblDescription.setHeight("-1px");
        lblDescription.setValue(BundleUtils.getString("lb.deptstaff.desc"));
        gridLayoutDepartInfo.addComponent(lblDescription, 0, 1);

        // textArea_1
        textArea_1 = new TextArea();
        textArea_1.setImmediate(true);
        textArea_1.setWidth("100.0%");
        textArea_1.setHeight("-1px");
        textArea_1.setMaxLength(300);
        textArea_1.setStyleName("notRequireStyle");
        gridLayoutDepartInfo.addComponent(textArea_1, 1, 1, 3, 1);

        // lblStatus
        lblStatus = new Label();
        lblStatus.setImmediate(true);
        lblStatus.setWidth("100.0%");
        lblStatus.setHeight("-1px");
        lblStatus.setValue(BundleUtils.getString("lb.deptstaff.common.status"));
        gridLayoutDepartInfo.addComponent(lblStatus, 0, 2);

        // cbxStatus
        cbxStatus = new ComboBox();
        cbxStatus.setImmediate(true);
        cbxStatus.setTextInputAllowed(false);
        cbxStatus.setFilteringMode(FilteringMode.OFF);
        cbxStatus.setWidth("100.0%");
        cbxStatus.setHeight("-1px");
        cbxStatus.setRequired(true);
        gridLayoutDepartInfo.addComponent(cbxStatus, 1, 2);

        // lblPhoneNumber
        lblPhoneNumber = new Label();
        lblPhoneNumber.setImmediate(true);
        lblPhoneNumber.setWidth("100.0%");
        lblPhoneNumber.setHeight("-1px");
        lblPhoneNumber.setValue(BundleUtils.getString("lb.deptstaff.common.phone"));
        gridLayoutDepartInfo.addComponent(lblPhoneNumber, 2, 2);

        // txtPhoneNumber
        txtPhoneNumber = new TextField();
        txtPhoneNumber.setImmediate(true);
        txtPhoneNumber.setInputPrompt(BundleUtils.getString("common.phone.format"));
        txtPhoneNumber.setWidth("100.0%");
        txtPhoneNumber.setHeight("-1px");
        txtPhoneNumber.setMaxLength(100);
        //message
        //          StringBuilder messageErrorOrder = new StringBuilder();
        //        messageErrorOrder.append(BundleUtils.getString("lb.deptstaff.common.phone"));
        //        messageErrorOrder.append(BundleUtils.getString(" "));
        //        messageErrorOrder.append(BundleUtils.getString("message.error.phoneformat"));
        //        txtPhoneNumber.addValidator(new RegexpValidator("^\\(?(\\d{3,4})\\)?[- ]?(\\d{3})[- ]?(\\d{4})$", messageErrorOrder.toString()));
        txtPhoneNumber.setStyleName("notRequireStyle");
        gridLayoutDepartInfo.addComponent(txtPhoneNumber, 3, 2);

        // lblFax
        //        lblFax = new Label();
        //        lblFax.setImmediate(true);
        //        lblFax.setWidth("100.0%");
        //        lblFax.setHeight("-1px");
        //        lblFax.setValue(BundleUtils.getString("lb.deptstaff.fax"));
        //        gridLayoutDepartInfo.addComponent(lblFax, 0, 4);

        // txtFax
        //        txtFax = new TextField();
        //        txtFax.setImmediate(true);
        //        txtFax.setWidth("100.0%");
        //        txtFax.setHeight("-1px");
        //        txtFax.setMaxLength(100);
        //message
        //        StringBuilder messageErrorFax = new StringBuilder();
        //        messageErrorFax.append(BundleUtils.getString("lb.deptstaff.fax"));
        //        messageErrorFax.append(BundleUtils.getString(" "));
        //        messageErrorFax.append(BundleUtils.getString("message.error.numberformat"));
        //        txtFax.addValidator(new RegexpValidator("[0-9]+", messageErrorFax.toString()));
        //        txtFax.setStyleName("notRequireStyle");
        //        gridLayoutDepartInfo.addComponent(txtFax, 1, 4);

        // lblEmail
        lblEmail = new Label();
        lblEmail.setImmediate(true);
        lblEmail.setWidth("100.0%");
        lblEmail.setHeight("-1px");
        lblEmail.setValue(BundleUtils.getString("lb.deptstaff.common.email"));
        gridLayoutDepartInfo.addComponent(lblEmail, 2, 3);

        // txtEmail
        txtEmail = new TextField();
        txtEmail.setImmediate(true);
        txtEmail.addValidator(new EmailValidator(BundleUtils.getString("common.error.email")));
        txtEmail.setRequiredError(BundleUtils.getString("common.error.email"));
        txtEmail.setInputPrompt(BundleUtils.getString("common.email.hint.format"));
        txtEmail.setWidth("100.0%");
        txtEmail.setHeight("-1px");
        txtEmail.setMaxLength(100);
        txtEmail.setStyleName("notRequireStyle");
        gridLayoutDepartInfo.addComponent(txtEmail, 3, 3);

        // lblAddress
        lblAddress = new Label();
        lblAddress.setImmediate(true);
        lblAddress.setWidth("100.0%");
        lblAddress.setHeight("-1px");
        lblAddress.setValue(BundleUtils.getString("lb.deptstaff.dept.addr"));
        gridLayoutDepartInfo.addComponent(lblAddress, 0, 4);

        // txtAddress
        txtAddress = new TextField();
        txtAddress.setImmediate(true);
        txtAddress.setWidth("100.0%");
        txtAddress.setHeight("-1px");
        txtAddress.setMaxLength(300);
        //        txtAddress.addValidator(new StringLengthValidator(BundleUtils.getString("common.error.length"), 0, 200, true));
        txtAddress.setRequired(true);
        txtAddress.setStyleName("notRequireStyle");
        gridLayoutDepartInfo.addComponent(txtAddress, 1, 4, 3, 4);

        // lblContact
        //        lblContact = new Label();
        //        lblContact.setImmediate(true);
        //        lblContact.setWidth("100.0%");
        //        lblContact.setHeight("-1px");
        //        lblContact.setValue(BundleUtils.getString("lb.deptstaff.contact.person"));
        //        gridLayoutDepartInfo.addComponent(lblContact, 0, 5);
        //
        //        // txtContact
        //        txtContact = new TextField();
        //        txtContact.setImmediate(true);
        //        txtContact.setWidth("100.0%");
        //        txtContact.setHeight("-1px");
        //        txtContact.setMaxLength(200);
        //        txtContact.setStyleName("notRequireStyle");
        //        gridLayoutDepartInfo.addComponent(txtContact, 1, 5, 3, 5);

        return gridLayoutDepartInfo;
    }

    @AutoGenerated
    private HorizontalLayout buildHorizontalLayoutButton() {
        // common part: create layout
        horizontalLayoutButton = new HorizontalLayout();
        horizontalLayoutButton.setImmediate(true);
        horizontalLayoutButton.setWidth("100.0%");
        horizontalLayoutButton.setHeight("-1px");
        horizontalLayoutButton.setMargin(true);
        horizontalLayoutButton.setSpacing(true);

        // btnSave
        btnSave = new Button();
        btnSave.setCaption(BundleUtils.getString("common.button.save"));
        btnSave.setImmediate(true);
        btnSave.setWidth("-1px");
        btnSave.setHeight("-1px");
        btnSave.setIcon(new ThemeResource("img/save_icon.png"));
        horizontalLayoutButton.addComponent(btnSave);
        horizontalLayoutButton.setComponentAlignment(btnSave, new Alignment(34));

        // btnCancel
        btnCancel = new Button();
        btnCancel.setCaption(BundleUtils.getString("common.button.cancel"));
        btnCancel.setImmediate(true);
        btnCancel.setWidth("-1px");
        btnCancel.setHeight("-1px");
        btnCancel.setIcon(new ThemeResource("img/cancel_icon.png"));
        horizontalLayoutButton.addComponent(btnCancel);
        horizontalLayoutButton.setComponentAlignment(btnCancel, new Alignment(33));

        return horizontalLayoutButton;
    }

    public Button getBtnSave() {
        return btnSave;
    }

    public void setBtnSave(Button btnSave) {
        this.btnSave = btnSave;
    }

    public Button getBtnCancel() {
        return btnCancel;
    }

    public void setBtnCancel(Button btnCancel) {
        this.btnCancel = btnCancel;
    }

    //    public TextField getTxtContact() {
    //        return txtContact;
    //    }
    //
    //    public void setTxtContact(TextField txtContact) {
    //        this.txtContact = txtContact;
    //    }

    public TextField getTxtAddress() {
        return txtAddress;
    }

    public void setTxtAddress(TextField txtAddress) {
        this.txtAddress = txtAddress;
    }

    public TextField getTxtEmail() {
        return txtEmail;
    }

    public void setTxtEmail(TextField txtEmail) {
        this.txtEmail = txtEmail;
    }

    //    public TextField getTxtFax() {
    //        return txtFax;
    //    }
    //
    //    public void setTxtFax(TextField txtFax) {
    //        this.txtFax = txtFax;
    //    }

    public TextField getTxtPhoneNumber() {
        return txtPhoneNumber;
    }

    public void setTxtPhoneNumber(TextField txtPhoneNumber) {
        this.txtPhoneNumber = txtPhoneNumber;
    }

    public ComboBox getCbxStatus() {
        return cbxStatus;
    }

    public void setCbxStatus(ComboBox cbxStatus) {
        this.cbxStatus = cbxStatus;
    }

    public TextArea getTextArea_1() {
        return textArea_1;
    }

    public void setTextArea_1(TextArea textArea_1) {
        this.textArea_1 = textArea_1;
    }

    public TextField getTxtDepartmentName() {
        return txtDepartmentName;
    }

    public void setTxtDepartmentName(TextField txtDepartmentName) {
        this.txtDepartmentName = txtDepartmentName;
    }

    public TextField getTxtDepartmentCode() {
        return txtDepartmentCode;
    }

    public void setTxtDepartmentCode(TextField txtDepartmentCode) {
        this.txtDepartmentCode = txtDepartmentCode;
    }

    public DepartmentDTO getDepartmentDTO() {
        return departmentDTO;
    }

    public void setDepartmentDTO(DepartmentDTO departmentDTO) {
        this.departmentDTO = departmentDTO;
    }

    //    public MappingCombobox getComboDeptTopLevel() {
    //        return comboDeptTopLevel;
    //    }
    //
    //    public void setComboDeptTopLevel(MappingCombobox comboDeptTopLevel) {
    //        this.comboDeptTopLevel = comboDeptTopLevel;
    //    }

}