com.squadd.UI.EditWindow.java Source code

Java tutorial

Introduction

Here is the source code for com.squadd.UI.EditWindow.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.squadd.UI;

import com.squadd.javaBeans.Group;
import com.squadd.javaBeans.Place;
import com.squadd.managers.DBManager;
import com.squadd.technical.Display;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.Label;
import com.vaadin.ui.Window;
import java.util.Date;

/**
 *
 * @author SharkNado
 */
public class EditWindow extends Window {
    private EditInfoLayout edit;
    private Label info;
    private Label place;
    private Label date;
    private Label descr;
    private Group gr;

    public EditWindow(Group gr, Label info, Label place, Label date, Label descr) {
        this.gr = gr;
        edit = new EditInfoLayout();
        this.info = info;
        this.place = place;
        this.date = date;
        this.descr = descr;
        setContent(edit);
        setWidth(Display.width * 0.35 + "px");
        center();
        configureActions();
    }

    private void configureActions() {
        Button cancel = edit.getCancel();
        Button submit = edit.getSubmit();

        ClickListener canc = new ClickListener() {
            @Override
            public void buttonClick(Button.ClickEvent event) {
                close();
            }

        };

        cancel.addClickListener(canc);

        ClickListener sub = new ClickListener() {
            @Override
            public void buttonClick(Button.ClickEvent event) {
                Group grp = new Group();
                grp.setGroupId(gr.getGroupId());
                if (!(edit.getGrName().getValue().isEmpty())) {
                    gr.setName(edit.getGrName().getValue());
                }

                if (!(edit.getPlace().getValue().isEmpty())) {
                    Place pl = gr.getPlaceId();
                    pl.setCity(edit.getPlace().getValue());
                    gr.setPlaceId(pl);
                }

                if (!(edit.getDescr().getValue().isEmpty())) {
                    gr.setDescription(edit.getDescr().getValue());
                }

                if (!(edit.getDate().getValue() == null)) {
                    gr.setTime(edit.getDate().getValue());
                }

                info.setValue("Group Name: " + gr.getName());
                place.setValue("Place Name: " + gr.getPlaceId().getCity());
                descr.setValue("Description: " + gr.getDescription());
                date.setValue("Date: " + gr.getTime().toString());

                DBManager db = new DBManager();
                db.add(gr);
                close();
            }

        };

        submit.addClickListener(sub);
    }
}