Example usage for com.vaadin.server VaadinSession getCurrent

List of usage examples for com.vaadin.server VaadinSession getCurrent

Introduction

In this page you can find the example usage for com.vaadin.server VaadinSession getCurrent.

Prototype

public static VaadinSession getCurrent() 

Source Link

Document

Gets the currently used session.

Usage

From source file:ch.bfh.ti.soed.hs16.srs.purple.controller.LoginController.java

License:Open Source License

/**
 * Function checks if a user is logged in in the current vaadin session
 *
 * @return true if the user is logged in - false otherwise.
 *//*from  w  ww. j ava2 s .  c  om*/
public boolean isUserLoggedInOnSession() {
    if (VaadinSession.getCurrent() != null
            && VaadinSession.getCurrent().getAttribute(USER_SESSION_ATTRIBUTE) != null) {
        return true;
    }
    return false;
}

From source file:ch.bfh.ti.soed.hs16.srs.purple.controller.LoginController.java

License:Open Source License

/**
 * Function removes the logged in user from the session.
 */
public void logout() {
    VaadinSession.getCurrent().setAttribute(USER_SESSION_ATTRIBUTE, null);
}

From source file:ch.bfh.ti.soed.hs16.srs.purple.view.ReservationView.java

License:Open Source License

/**
 * Shows the popup window where a reservation can be modified, deleted or inserted
 * @param res The Reservation Object (for a new reservation, fill the startDate with the current Timestamp!)
 *//*w  ww .j a  v a 2s .co m*/
@SuppressWarnings("serial")
private void showPopup(Reservation res) {
    this.res = res; //Update the member
    boolean newRes = res.getReservationID() > 0 ? false : true;
    boolean isHost = isHost(actualUser, res.getHostList());
    boolean isParticipant = isHost(actualUser, res.getParticipantList());
    final GridLayout gridLayout = new GridLayout(3, 5);
    ValueChangeListener vcl = new ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            List<Room> roomList = resCont.getAllFreeRooms(new Timestamp(startDate.getValue().getTime()),
                    new Timestamp(endDate.getValue().getTime()));
            if (ReservationView.this.res.getReservationID() > 0) {
                System.out.println("Aktuellen Raum");
                rooms.addItem(ReservationView.this.res.getRoom().getRoomID());
                rooms.setItemCaption(ReservationView.this.res.getRoom().getRoomID(),
                        ReservationView.this.res.getRoom().getName() + " ("
                                + ReservationView.this.res.getRoom().getNumberOfSeats() + " Pltze)");
                rooms.select(ReservationView.this.res.getRoom().getRoomID());
            }
            for (int i = 0; i < roomList.size(); i++) {
                rooms.addItem(roomList.get(i).getRoomID());
                String caption = roomList.get(i).getName() + " (" + roomList.get(i).getNumberOfSeats()
                        + " Pltze)";
                rooms.setItemCaption(roomList.get(i).getRoomID(), caption);
            }
            if (ReservationView.this.res.getReservationID() <= 0 && actualRoom != null)
                rooms.select(actualRoom.getRoomID());
        }
    };
    popUpWindow = new Window();
    popUpWindow.center();
    popUpWindow.setModal(true);
    startDate = new DateField("Startzeit");
    startDate.setLocale(VaadinSession.getCurrent().getLocale());
    startDate.setValue(res.getStart());
    startDate.addValueChangeListener(vcl);
    startDate.setDateFormat("dd.MM.yyyy HH:mm");
    startDate.setResolution(Resolution.HOUR);
    endDate = new DateField("Endzeit");
    endDate.setValue(res.getEnd());
    endDate.addValueChangeListener(vcl);
    endDate.setDateFormat("dd.MM.yyyy HH:mm");
    endDate.setLocale(VaadinSession.getCurrent().getLocale());
    endDate.setResolution(Resolution.HOUR);
    title = new TextField("Titel");
    title.setValue(res.getTitle());
    title.setWidth(100, Unit.PERCENTAGE);
    description = new TextArea("Beschreibung");
    description.setValue(res.getDescription());
    description.setRows(3);
    description.setWidth(100, Unit.PERCENTAGE);
    hosts = new ListSelect("Reservierender");
    hosts.setMultiSelect(true);
    hosts.clear();
    for (int i = 0; i < hostList.size(); i++) {
        hosts.addItem(hostList.get(i).getUserID());
        hosts.setItemCaption(hostList.get(i).getUserID(), hostList.get(i).getUsername());
    }
    //select the hosts in list
    if (!newRes) {
        List<User> resHosts = res.getHostList();
        for (int i = 0; i < resHosts.size(); i++)
            for (int y = 0; y < hostList.size(); y++)
                if (hostList.get(y).getUserID() == resHosts.get(i).getUserID())
                    hosts.select(resHosts.get(i).getUserID());
    } else
        hosts.select(actualUser.getUserID());
    hosts.select(0);
    hosts.setRows(hostList.size() > 5 ? 5 : hostList.size());
    participantList = new ListSelect("Teilnehmer");
    participantList.setMultiSelect(true);
    participantList.clear();

    for (int i = 0; i < participant.size(); i++) {
        participantList.addItem(participant.get(i).getUserID());
        participantList.setItemCaption(participant.get(i).getUserID(), participant.get(i).getUsername());
    }
    //select the participants in list
    if (!newRes) {
        List<User> resPart = res.getParticipantList();
        for (int i = 0; i < resPart.size(); i++)
            for (int y = 0; y < participant.size(); y++)
                if (participant.get(y).getUserID() == resPart.get(i).getUserID())
                    participantList.select(resPart.get(i).getUserID());
    }
    participantList.setRows(participant.size() > 5 ? 5 : participant.size());
    rooms = new NativeSelect("Raum");
    rooms.setNullSelectionAllowed(false);
    rooms.removeAllItems();
    List<Room> roomList = resCont.getAllFreeRooms(new Timestamp(startDate.getValue().getTime()),
            new Timestamp(endDate.getValue().getTime()));
    if (!newRes) {
        rooms.addItem(res.getRoom().getRoomID());
        rooms.setItemCaption(res.getRoom().getRoomID(),
                res.getRoom().getName() + " (" + res.getRoom().getNumberOfSeats() + " Pltze)");
        rooms.select(res.getRoom().getRoomID());
    }
    for (int i = 0; i < roomList.size(); i++) {
        rooms.addItem(roomList.get(i).getRoomID());
        String caption = roomList.get(i).getName() + " (" + roomList.get(i).getNumberOfSeats() + " Pltze)";
        rooms.setItemCaption(roomList.get(i).getRoomID(), caption);
    }
    if (newRes && actualRoom != null)
        rooms.select(actualRoom.getRoomID());
    saveButton = new Button("Speichern");
    saveButton.addClickListener(clButton);
    deleteButton = new Button("Lschen");
    deleteButton.addClickListener(clButton);
    deleteButton.setVisible(res.getReservationID() > 0 ? true : false);
    if (!newRes)
        setEditable(false);
    gridLayout.addComponent(startDate, 0, 0);
    gridLayout.addComponent(endDate, 0, 1);
    gridLayout.addComponent(hosts, 1, 0, 1, 1);
    gridLayout.addComponent(participantList, 2, 0, 2, 1);
    gridLayout.addComponent(title, 0, 2);
    gridLayout.addComponent(rooms, 1, 2, 2, 2);
    gridLayout.addComponent(description, 0, 3, 1, 3);
    if (roomList.size() == 0)
        saveButton.setEnabled(false);
    if (isHost || newRes) //show buttons for edit and delete only if the user is host or its a new reservation
    {
        gridLayout.addComponent(saveButton, 0, 4);
        gridLayout.addComponent(deleteButton, 1, 4);
    }
    if (isParticipant) //show buttons for accept oder decline a reservation
    {
        acceptButton = new Button("Zusagen");
        rejectButton = new Button("Absagen");
        acceptButton.addClickListener(clButton);
        rejectButton.addClickListener(clButton);
        if (isHost(actualUser, res.getAcceptedParticipantsList())) {
            acceptButton.setEnabled(false);
            rejectButton.setEnabled(true);
        } else {
            rejectButton.setEnabled(false);
            acceptButton.setEnabled(true);
        }
        gridLayout.addComponent(acceptButton, 0, 4);
        gridLayout.addComponent(rejectButton, 1, 4);
    }
    gridLayout.setSpacing(true);
    gridLayout.setMargin(new MarginInfo(false, false, false, true));
    gridLayout.setWidth(100, Unit.PERCENTAGE);
    popUpWindow.setContent(gridLayout);
    popUpWindow.setWidth("600px");
    popUpWindow.setHeight("450px");
    popUpWindow.setCaption(res.getReservationID() > 0 ? "Reservierungsdetails" : "Neue Reservierung");
    UI.getCurrent().addWindow(popUpWindow);
}

From source file:ch.bfh.ti.soed.hs16.srs.purple.view.ReservationView.java

License:Open Source License

/**
 * Function shows the view on the content panel
 * @param content - the content to be displayed.
 *//*  w w  w  .j a  v a  2 s.c  o m*/
@Override
public void display(Component content) {
    actualUser = resCont
            .getSessionUser((String) VaadinSession.getCurrent().getAttribute(USER_SESSION_ATTRIBUTE));
    calendarUpdate();
    Panel contentPanel = (Panel) content;
    contentPanel.setContent(layout);
}

From source file:ch.bfh.ti.soed.hs16.srs.purple.view.UserProfileView.java

License:Open Source License

/**
 * Function fills form with current user.
 *///from   w  w  w .  java2 s.co m
private void fillForm() {
    this.currentDbUser = this.userProfileController.getUserForView(
            VaadinSession.getCurrent().getAttribute(LoginController.USER_SESSION_ATTRIBUTE).toString());
    this.lastName.setValue(this.currentDbUser.getLastName());
    this.firstName.setValue(this.currentDbUser.getFirstName());
    this.email.setValue(this.currentDbUser.getEmailAddress());
    this.username.setValue(this.currentDbUser.getUsername());
    this.password.setValue("");
    this.passwordReply.setValue("");
    this.function.setValue(this.currentDbUser.getFunction());
}

From source file:com.anphat.customer.controller.CustomerContactController.java

private void addButtonAddContactOnTblTermInfo(CustomPageTableFilter tbl) {
    tbl.addGeneratedColumn("btnAddContact", new CustomTable.ColumnGenerator() {
        @Override/*w  ww.j a v  a  2 s . c o  m*/
        public Object generateCell(CustomTable source, Object itemId, Object columnId) {
            TermInformationDTO term = (TermInformationDTO) itemId;
            CustomerContactDTO contactDTO = term.convert2CustomerContact();
            StaffDTO staff = (StaffDTO) VaadinSession.getCurrent().getAttribute("staff");
            contactDTO.setStaffCode(staff.getCode());
            Button btnAdd = new Button(FontAwesome.PHONE);
            btnAdd.addStyleName(Runo.BUTTON_LINK);
            addBtnAddContactClickListener(btnAdd, contactDTO);
            return btnAdd;
        }
    });
}

From source file:com.anphat.customer.controller.CustomerContactController.java

private CustomerCareHistoryDTO getCustomerStatus(TermInformationDTO term) {
    StaffDTO staff = (StaffDTO) VaadinSession.getCurrent().getAttribute("staff");

    CustomerCareHistoryDTO careHistoryDTO = new CustomerCareHistoryDTO();
    careHistoryDTO.setMineName(term.getMineName());
    careHistoryDTO.setCustId(term.getCustId());
    careHistoryDTO.setTaxCode(term.getTaxCode());
    careHistoryDTO.setStaffId(staff.getStaffId());
    careHistoryDTO.setStaffCode(staff.getCode());
    //Tam thoi fix dich vu
    careHistoryDTO.setService(term.getService());
    careHistoryDTO.setCreateDate(DateUtil.date2ddMMyyyyHHMMss(new Date()));
    careHistoryDTO.setNotes("");
    //        careHistoryDTO.setStatus(Constants.CARE_HIS_REPORT);
    careHistoryDTO.setTelNumber(DataUtil.getStringNullOrZero(term.getPhone()));
    return careHistoryDTO;
}

From source file:com.anphat.customer.controller.CustomerContactController.java

private void getListDatasWithCustomer(CustomerDTO customer) {
    if (customer != null && !DataUtil.isStringNullOrEmpty(customer.getTaxCode())) {
        try {/*from  ww w. j  a v a 2s.c om*/
            StaffDTO staff = (StaffDTO) VaadinSession.getCurrent().getAttribute("staff");
            String staffCode;
            //Neu la admin thi cho phep lay du lieu cua tat ca cac thanh vien
            if (!DataUtil.isAdmin(staff)) {
                staffCode = staff.getCode();
            } else {
                staffCode = null;
            }
            CustomerInfomationDTO customerInfomationDTO = WSCustomer.getCustInfo(customer.getTaxCode(),
                    staffCode, customer.getMineName());
            if (customerInfomationDTO != null) {
                lstTermInfors = customerInfomationDTO.getLstTermInformationDTOs();
                //                    lstTermInfors = filterTermInformation(lstTermInfors);
                lstCustContact = customerInfomationDTO.getLstCustomerContacts();
                lstCustCareHistory = customerInfomationDTO.getLstCustomerCareHistoryDTOs();
                lstCustomerStatus = customerInfomationDTO.getLstCustomerStatusDTOs();
            }
        } catch (Exception e) {
            lstTermInfors = null;
            lstCustContact = null;
            lstCustCareHistory = null;
            lstCustomerStatus = null;
            e.printStackTrace();
        }
    } else {
        lstTermInfors = null;
        lstCustContact = null;
        lstCustCareHistory = null;
        lstCustomerStatus = null;
    }
}

From source file:com.anphat.customer.controller.CustomerContactController.java

public void updateCustomerTable(CustomerCareHistoryDTO careHistoryDTO) {
    StaffDTO staff = (StaffDTO) VaadinSession.getCurrent().getAttribute("staff");
    if (!DataUtil.isAdmin(staff)) {
        CustomerStatusDTO cs = lstCustomerStatus.get(0);
        cs.setLastUpdated(careHistoryDTO.getCreateDate());
        cs.setStatus(careHistoryDTO.getStatus());
        cs.setLastNotes(careHistoryDTO.getNotes());
        try {//from w  w w.  j  ava  2  s.  c o  m
            String updateResult = WSCustomerStatus.updateCustomerStatus(cs);
        } catch (Exception e) {
        }
    }
    //Update table Danh sach khach hang
    firstSelectedCust.setStatus(careHistoryDTO.getStatus());
    firstSelectedCust.setCreateDate(careHistoryDTO.getCreateDate());
    firstSelectedCust.setNotes(careHistoryDTO.getNotes());
    tblCustomer.getItem(firstSelectedCust).getItemProperty("notes").setValue(careHistoryDTO.getNotes());
    tblCustomer.getItem(firstSelectedCust).getItemProperty("createDate")
            .setValue(careHistoryDTO.getCreateDate());
    tblCustomer.getItem(firstSelectedCust).getItemProperty("status").setValue(careHistoryDTO.getStatus());

}

From source file:com.anphat.customer.controller.CustomerInfoUploader.java

@Override
public void uploadFile() {
    try {/*w  w  w.ja  va 2s.  c  om*/
        List lstUpload;
        List<ValidateCells> lstValidateCells = new ArrayList<>();
        lstValidateCells.add(new ValidateCells(DataUtil.STRING, true, 14));//mst
        lstValidateCells.add(new ValidateCells(DataUtil.STRING, true, 200));//Ten khach hang
        lstValidateCells.add(new ValidateCells(DataUtil.STRING, false, 50));// CQT - Tinh
        lstValidateCells.add(new ValidateCells(DataUtil.DATE, false, 14));// Ngay dang ky kkt
        lstValidateCells.add(new ValidateCells(DataUtil.DATE, false, 14));// Ngay kkt gan nhat
        lstValidateCells.add(new ValidateCells(DataUtil.STRING, false, 50));// chi cuc thue             
        lstValidateCells.add(new ValidateCells(DataUtil.STRING, false, 25));//Loai khach hang
        lstValidateCells.add(new ValidateCells(DataUtil.STRING, false, 25));//so dien thoai
        lstValidateCells.add(new ValidateCells(DataUtil.STRING, false, 25));//fax
        lstValidateCells.add(new ValidateCells(DataUtil.STRING, false, 25));//Email
        lstValidateCells.add(new ValidateCells(DataUtil.STRING, false, 50));//So tai khoan
        lstValidateCells.add(new ValidateCells(DataUtil.STRING, false, 50));//Ngan hang
        lstValidateCells.add(new ValidateCells(DataUtil.STRING, false, 50));//Dai ly thue
        lstValidateCells.add(new ValidateCells(DataUtil.STRING, false, 200));//Dia chi kinh doanh
        lstValidateCells.add(new ValidateCells(DataUtil.STRING, false, 200));//Dia chi tru so
        lstValidateCells.add(new ValidateCells(DataUtil.STRING, false, 100));//Tn ng?i i din
        lstValidateCells.add(new ValidateCells(DataUtil.STRING, false, 25));//Chng minh th
        lstValidateCells.add(new ValidateCells(DataUtil.STRING, false, 200));//Mo ta
        lstUpload = DataUtil.isValidExcells(mimeType, tempFile, 0, 1, 0, 17, 3, lstValidateCells);
        if (lstUpload == null) {
            Notification.show(BundleUtils.getString("valid.import.file"), Notification.Type.WARNING_MESSAGE);
            return;
        }
        staff = (StaffDTO) VaadinSession.getCurrent().getAttribute("staff");

        //LAY DANH DACH DU LIEU - CELL DA NHAP
        Object[] tmp;

        String taxCode; //Ma so thue
        String name; //Ten khach hang
        String taxAuthority; //C quan thu 
        String dateRegister; //Ngay dang ky kkt
        String lastUploadDate; //Ngay kkt gan nhat
        String taxDepartment; //Chi cc thu
        String custType; //Loai khach hang
        String telNumber; //So dien thoai
        String fax; //So fax
        String email; //Email
        String accountNo; //So tai khoan
        String bankName; //Ngan hang
        String agency; //Dai ly thue
        String deployAddress;//Dia chi kinh doanh
        String officeAddress; //Dia chi tru so
        String representativeName; // Tn ng?i i din
        String representativeId = ""; //Chng minh th
        String description; //Mo ta

        String staffName = staff.getName(); //Nhan vien tai len
        lstUploaded = new ArrayList<>();
        CustomerDTO tempObject;
        List<String> lstTaxCodes = new ArrayList<>();
        for (Object object : lstUpload) {
            tmp = (Object[]) object;
            if (!DataUtil.isNullObject(tmp)) {
                taxCode = DataUtil.getStringNullOrZero(String.valueOf(tmp[0]));
                if (!lstTaxCodes.contains(taxCode) && !"null".equalsIgnoreCase(taxCode)) {
                    lstTaxCodes.add(taxCode);
                    name = DataUtil.getStringNullOrZero(String.valueOf(tmp[1]));
                    taxAuthority = DataUtil.getStringNullOrZero(String.valueOf(tmp[2]));
                    dateRegister = DataUtil.getStringNullOrZero(String.valueOf(tmp[3]));
                    lastUploadDate = DataUtil.getStringNullOrZero(String.valueOf(tmp[4]));
                    taxDepartment = DataUtil.getStringNullOrZero(String.valueOf(tmp[5]));
                    custType = DataUtil.getStringNullOrZero(String.valueOf(tmp[6]));
                    telNumber = DataUtil.getStringNullOrZero(String.valueOf(tmp[7]));
                    fax = DataUtil.getStringNullOrZero(String.valueOf(tmp[8]));
                    email = DataUtil.getStringNullOrZero(String.valueOf(tmp[9]));
                    accountNo = DataUtil.getStringNullOrZero(String.valueOf(tmp[10]));
                    bankName = DataUtil.getStringNullOrZero(String.valueOf(tmp[11]));
                    agency = DataUtil.getStringNullOrZero(String.valueOf(tmp[12]));
                    deployAddress = DataUtil.getStringNullOrZero(String.valueOf(tmp[13]));
                    officeAddress = DataUtil.getStringNullOrZero(String.valueOf(tmp[14]));
                    representativeName = DataUtil.getStringNullOrZero(String.valueOf(tmp[15]));
                    representativeId = DataUtil.getStringNullOrZero(String.valueOf(tmp[16]));
                    description = DataUtil.getStringNullOrZero(String.valueOf(tmp[17]));

                    tempObject = new CustomerDTO(taxCode, name, taxAuthority, dateRegister, lastUploadDate,
                            taxDepartment, custType, telNumber, fax, email, accountNo, bankName, agency,
                            deployAddress, officeAddress, representativeName, representativeId, description,
                            staffName);
                    lstUploaded.add(tempObject);
                }
            }
        }
        if (!DataUtil.isListNullOrEmpty(lstUploaded)) {
            //                lstUploaded = removeDupplicationDatas(lstUploaded);
            List<CustomerDTO> lstCustomerExisted = checkCustomersExisted(lstUploaded);

            //                List<CustomerDTO> lstCustomerHTKK = getInfoOfCustomerFromIHTKK(lstUploaded);

            if (DataUtil.isListNullOrEmpty(lstCustomerExisted)) {
                container = new BeanItemContainer(CustomerDTO.class);
                //                    mapTaxCode2Cust = DataUtil.buildHasmap(lstCustomerHTKK, "taxCode");
                CustomerDTO temp;
                //                    for (CustomerDTO c : lstUploaded) {
                //                        if (mapTaxCode2Cust.containsKey(c.getTaxCode())) {
                //                            temp = mapTaxCode2Cust.get(c.getTaxCode());
                //                            c.setName(temp.getName());
                //                            c.setTaxAuthority(temp.getTaxAuthority() + "00");
                //                        }
                //                    }
                container.addAll(lstUploaded);
                CommonFunctionTableFilter.refreshTable(tblPanel, HEADER, container);
            } else {
                mapTaxCode2Cust = DataUtil.buildHasmap(lstCustomerExisted, "taxCode");
                //                    Map<String, CustomerDTO> mapTaxCode2CustIHTKK = DataUtil.buildHasmap(lstCustomerHTKK, "taxCode");
                CustomerDTO temp;
                String taxCode1;
                for (CustomerDTO c : lstUploaded) {
                    taxCode1 = c.getTaxCode();
                    if (mapTaxCode2Cust.containsKey(taxCode1)) {
                        temp = mapTaxCode2Cust.get(taxCode1);
                        c.setCustId(temp.getCustId());
                        //                            c.setTaxAuthority(temp.getTaxAuthority());
                        //                            if (Objects.equal("90000", temp.getTaxAuthority())) {
                        //                                if (mapTaxCode2CustIHTKK.containsKey(taxCode1)) {
                        //                                    temp = mapTaxCode2CustIHTKK.get(taxCode1);
                        //                                    c.setTaxAuthority(temp.getTaxAuthority() + "00");
                        //                                }
                        //                            }

                    } else {
                        //                            if (mapTaxCode2CustIHTKK.containsKey(taxCode1)) {
                        //                                temp = mapTaxCode2CustIHTKK.get(taxCode1);
                        //                                if (!DataUtil.isStringNullOrEmpty(temp.getName())) {
                        //                                    c.setName(temp.getName());
                        //                                }
                        //                                if (!DataUtil.isStringNullOrEmpty(temp.getTaxAuthority())) {
                        //                                    c.setTaxAuthority(temp.getTaxAuthority() + "00");
                        //                                }
                        //                            }
                    }
                    //                        lstInserts.add(c);
                }

                container = new BeanItemContainer(CustomerDTO.class);
                container.addAll(lstUploaded);
                CommonFunctionTableFilter.refreshTable(tblPanel, HEADER, container);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        wp.close();
        UI.getCurrent().setPollInterval(-1);
    }
}