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:com.dungnv.streetfood.ui.CategoryItemUI.java

private void buildAction() {

    String info = !StringUtils.isNullOrEmpty(item.getId())
            ? "<b>" + com.kbdunn.vaadin.addons.fontawesome.FontAwesome.BARCODE.getHtml() + " " + item.getId()
                    + "</b>"
            : "<b>" + com.kbdunn.vaadin.addons.fontawesome.FontAwesome.BARCODE.getHtml() + " --</b>";

    if (!StringUtils.isNullOrEmpty(info)) {
        lbInfo.setCaption(info);//from   ww w.j a v  a2  s.c  om
    }

    btnEdit.addClickListener((Button.ClickEvent event) -> {
        if (item != null) {
            CategoryInsert CategoryInsert = new CategoryInsert(item//
            , event.getButton().findAncestor(CategoryView.class)//
            , Constants.ACTION.UPDATE);
            CategoryInsert.setWidth("80%");
            CategoryInsert.setHeight("90%");
            CategoryInsert.setModal(true);
            FWUtils.reloadWindow(CategoryInsert);
            UI.getCurrent().addWindow(CategoryInsert);
        }
    });

    btnLink.addClickListener((Button.ClickEvent event) -> {
        if (item != null) {
            CategoryLink CategoryInsert = new CategoryLink(item);
            CategoryInsert.setWidth("80%");
            CategoryInsert.setHeight("75%");
            CategoryInsert.setModal(true);
            FWUtils.reloadWindow(CategoryInsert);
            UI.getCurrent().addWindow(CategoryInsert);
        }
    });

    btnDelete.addClickListener((Button.ClickEvent event) -> {
        ConfirmDialog.show(UI.getCurrent(), BundleUtils.getLanguage("lbl.confirm")//
        , BundleUtils.getLanguage("message.category.delete.confirm")//
        , BundleUtils.getLanguage("lbl.yes")//
        , BundleUtils.getLanguage("lbl.no")//
        , (ConfirmDialog cd) -> {
            if (cd.isConfirmed()) {
                UserDTO user = (UserDTO) VaadinSession.getCurrent().getAttribute(UserDTO.class.getName());
                ResultDTO result = ClientServiceImpl.getInstance().deleteCategory(user.getUsername()//
                , getLocale().getLanguage(), getLocale().getCountry(), null, itemId);
                if (result != null && Constants.SUCCESS.equals(result.getMessage())) {
                    mainView.onSearch(Boolean.TRUE);
                    UI.getCurrent().removeWindow(event.getButton().findAncestor(Window.class));
                } else {
                    Notification.show(
                            result == null || result.getKey() == null ? Constants.FAIL : result.getKey(),
                            Notification.Type.ERROR_MESSAGE);
                }
            }
        });
    });

}

From source file:com.dungnv.streetfood.ui.DishItemUI.java

public DishItemUI(DishDTO item, DishView mainView) {
    setLocale(VaadinSession.getCurrent().getLocale());
    this.mainView = mainView;
    this.item = item == null ? new DishDTO() : item;
    this.itemId = this.item.getId();
    init();//from  w ww.  j  ava 2  s  .co m
    buildAction();
}

From source file:com.dungnv.streetfood.ui.DishItemUI.java

private void buildAction() {

    if ("1".equals(item.getDishStatus())) {
        lbTitle.addStyleName("lb-status-active");
    } else {/*from  w  ww.  j a  v a 2  s  .  co  m*/
        lbTitle.addStyleName("lb-status-inActive");
    }

    String info = !StringUtils.isNullOrEmpty(item.getId())
            ? "<b>" + com.kbdunn.vaadin.addons.fontawesome.FontAwesome.BARCODE.getHtml() + " " + item.getId()
                    + "</b>"
            : "<b>" + com.kbdunn.vaadin.addons.fontawesome.FontAwesome.BARCODE.getHtml() + " --</b>";

    info += !StringUtils.isNullOrEmpty(item.getRating())
            ? "&nbsp|" + FontAwesome.STAR_O.getHtml() + "&nbsp&nbsp:&nbsp&nbsp" + item.getRating()
            : "&nbsp|" + FontAwesome.STAR_O.getHtml() + "&nbsp&nbsp:&nbsp&nbsp--";

    info += !StringUtils.isNullOrEmpty(item.getViewCount())
            ? "&nbsp|" + FontAwesome.EYE.getHtml() + "&nbsp&nbsp:&nbsp&nbsp" + item.getViewCount()
            : "&nbsp|" + FontAwesome.EYE.getHtml() + "&nbsp&nbsp:&nbsp&nbsp--";

    info += !StringUtils.isNullOrEmpty(item.getCommentCount())
            ? "&nbsp|" + FontAwesome.COMMENTS.getHtml() + "&nbsp&nbsp:&nbsp&nbsp" + item.getCommentCount()
            : "&nbsp|" + FontAwesome.COMMENTS.getHtml() + "&nbsp&nbsp:&nbsp&nbsp--";

    info += !StringUtils.isNullOrEmpty(item.getShareCount())
            ? "&nbsp|" + FontAwesome.SHARE_ALT.getHtml() + "&nbsp&nbsp:&nbsp&nbsp" + item.getShareCount()
            : "&nbsp|" + FontAwesome.SHARE_ALT.getHtml() + "&nbsp&nbsp:&nbsp&nbsp--";

    if (!StringUtils.isNullOrEmpty(info)) {
        lbInfo.setCaption(info);
    }

    btnEdit.addClickListener((Button.ClickEvent event) -> {
        if (item != null) {
            DishInsert dishInsert = new DishInsert(item//
            , event.getButton().findAncestor(DishView.class)//
            , Constants.ACTION.UPDATE);
            dishInsert.setWidth("80%");
            dishInsert.setHeight("90%");
            dishInsert.setModal(true);
            FWUtils.reloadWindow(dishInsert);
            UI.getCurrent().addWindow(dishInsert);
        }
    });

    btnLink.addClickListener((Button.ClickEvent event) -> {
        if (item != null) {
            DishLink dishLink = new DishLink(item);
            dishLink.setWidth("80%");
            dishLink.setHeight("75%");
            dishLink.setModal(true);
            FWUtils.reloadWindow(dishLink);
            UI.getCurrent().addWindow(dishLink);
        }
    });

    btnDelete.addClickListener((Button.ClickEvent event) -> {
        ConfirmDialog.show(UI.getCurrent(), BundleUtils.getLanguage("lbl.confirm")//
        , BundleUtils.getLanguage("message.category.delete.confirm")//
        , BundleUtils.getLanguage("lbl.yes")//
        , BundleUtils.getLanguage("lbl.no")//
        , (ConfirmDialog cd) -> {
            if (cd.isConfirmed()) {
                UserDTO user = (UserDTO) VaadinSession.getCurrent().getAttribute(UserDTO.class.getName());
                ResultDTO result = ClientServiceImpl.getInstance().deleteDish(user.getUsername()//
                , getLocale().getLanguage(), getLocale().getCountry(), null, Long.valueOf(itemId));
                if (result != null && Constants.SUCCESS.equals(result.getMessage())) {
                    mainView.onSearch(Boolean.TRUE);
                    UI.getCurrent().removeWindow(event.getButton().findAncestor(Window.class));
                } else {
                    Notification.show(
                            result == null || result.getKey() == null ? Constants.FAIL : result.getKey(),
                            Notification.Type.ERROR_MESSAGE);
                }
            }
        });
    });

}

From source file:com.dungnv.streetfood.ui.RestaurantItemUI.java

public RestaurantItemUI(RestaurantDTO item, RestaurantView mainView) {
    setLocale(VaadinSession.getCurrent().getLocale());
    this.mainView = mainView;
    this.item = item == null ? new RestaurantDTO() : item;
    this.itemId = this.item.getId();
    init();//from w w  w .j a va  2  s  . c om
    buildAction();
}

From source file:com.dungnv.streetfood.ui.RestaurantItemUI.java

private void buildAction() {

    if ("1".equals(item.getRestaurantStatus())) {
        lbTitle.addStyleName("lb-status-active");
    } else {/*from  w  w w .  j a v a  2s.c  om*/
        lbTitle.addStyleName("lb-status-inActive");
    }

    String info = !StringUtils.isNullOrEmpty(item.getId())
            ? "<b>" + com.kbdunn.vaadin.addons.fontawesome.FontAwesome.BARCODE.getHtml() + " " + item.getId()
                    + "</b>"
            : "<b>" + com.kbdunn.vaadin.addons.fontawesome.FontAwesome.BARCODE.getHtml() + " --</b>";

    info += !StringUtils.isNullOrEmpty(item.getRating())
            ? "&nbsp|" + FontAwesome.STAR_O.getHtml() + "&nbsp&nbsp:&nbsp&nbsp" + item.getRating()
            : "&nbsp|" + FontAwesome.STAR_O.getHtml() + "&nbsp&nbsp:&nbsp&nbsp--";

    info += !StringUtils.isNullOrEmpty(item.getViewCount())
            ? "&nbsp|" + FontAwesome.EYE.getHtml() + "&nbsp&nbsp:&nbsp&nbsp" + item.getViewCount()
            : "&nbsp|" + FontAwesome.EYE.getHtml() + "&nbsp&nbsp:&nbsp&nbsp--";

    info += !StringUtils.isNullOrEmpty(item.getCommentCount())
            ? "&nbsp|" + FontAwesome.COMMENTS.getHtml() + "&nbsp&nbsp:&nbsp&nbsp" + item.getCommentCount()
            : "&nbsp|" + FontAwesome.COMMENTS.getHtml() + "&nbsp&nbsp:&nbsp&nbsp--";

    info += !StringUtils.isNullOrEmpty(item.getShareCount())
            ? "&nbsp|" + FontAwesome.SHARE_ALT.getHtml() + "&nbsp&nbsp:&nbsp&nbsp" + item.getShareCount()
            : "&nbsp|" + FontAwesome.SHARE_ALT.getHtml() + "&nbsp&nbsp:&nbsp&nbsp--";
    //        
    //        info += !StringUtils.isNullOrEmpty(item.getOperatingTimeStart())
    //                ? "&nbsp|" + FontAwesome.CLOCK_O.getHtml() + "&nbsp&nbsp:&nbsp&nbsp" + item.getOperatingTimeStart() + " / "
    //                : "&nbsp|" + FontAwesome.CLOCK_O.getHtml() + "&nbsp&nbsp:&nbsp&nbsp--:--" + " / ";
    //        
    //        info += !StringUtils.isNullOrEmpty(item.getOperatingTimeEnd())
    //                ?  item.getOperatingTimeEnd() : "--:--" ;

    if (!StringUtils.isNullOrEmpty(info)) {
        lbInfo.setCaption(info);
    }

    btnEdit.addClickListener((Button.ClickEvent event) -> {
        if (item != null) {
            RestaurantInsert restaurantInsert = new RestaurantInsert(item//
            , event.getButton().findAncestor(RestaurantView.class)//
            , Constants.ACTION.UPDATE);
            restaurantInsert.setWidth("80%");
            restaurantInsert.setHeight("90%");
            restaurantInsert.setModal(true);
            FWUtils.reloadWindow(restaurantInsert);
            UI.getCurrent().addWindow(restaurantInsert);
        }
    });

    btnLink.addClickListener((Button.ClickEvent event) -> {
        if (item != null) {
            RestaurantLink restaurantLink = new RestaurantLink(item);
            restaurantLink.setWidth("80%");
            restaurantLink.setHeight("75%");
            restaurantLink.setModal(true);
            FWUtils.reloadWindow(restaurantLink);
            UI.getCurrent().addWindow(restaurantLink);
        }
    });

    btnDelete.addClickListener((Button.ClickEvent event) -> {
        ConfirmDialog.show(UI.getCurrent(), BundleUtils.getLanguage("lbl.confirm")//
        , BundleUtils.getLanguage("message.category.delete.confirm")//
        , BundleUtils.getLanguage("lbl.yes")//
        , BundleUtils.getLanguage("lbl.no")//
        , (ConfirmDialog cd) -> {
            if (cd.isConfirmed()) {
                UserDTO user = (UserDTO) VaadinSession.getCurrent().getAttribute(UserDTO.class.getName());
                ResultDTO result = ClientServiceImpl.getInstance().deleteRestaurant(user.getUsername()//
                , getLocale().getLanguage(), getLocale().getCountry(), null, Long.valueOf(itemId));
                if (result != null && Constants.SUCCESS.equals(result.getMessage())) {
                    mainView.onSearch(Boolean.TRUE);
                    UI.getCurrent().removeWindow(event.getButton().findAncestor(Window.class));
                } else {
                    Notification.show(
                            result == null || result.getKey() == null ? Constants.FAIL : result.getKey(),
                            Notification.Type.ERROR_MESSAGE);
                }
            }
        });
    });

}

From source file:com.dungnv.streetfood.ui.SlideShowItemUI.java

public SlideShowItemUI(SlideShowDTO item, SlideShowView mainView) {
    setLocale(VaadinSession.getCurrent().getLocale());
    this.mainView = mainView;
    this.item = item == null ? new SlideShowDTO() : item;
    this.itemId = this.item.getId();
    init();/*from w  w  w  . j av  a  2 s .  c om*/
    buildAction();
}

From source file:com.dungnv.streetfood.ui.SlideShowItemUI.java

private void buildAction() {

    lbTitle.addStyleName("lb-status-active");

    String info = "";

    if (!StringUtils.isNullOrEmpty(item.getId())) {
        info += StringUtils.isNullOrEmpty(info)
                ? FontAwesome.OUTDENT.getHtml() + "&nbsp&nbsp:&nbsp&nbsp" + item.getId()
                : "&nbsp|" + FontAwesome.OUTDENT.getHtml() + "&nbsp&nbsp:&nbsp&nbsp" + item.getId();
    }/*from w  w w. j a  va2  s. co  m*/

    if (!StringUtils.isNullOrEmpty(item.getValidFromGmt())) {
        info += StringUtils.isNullOrEmpty(info)
                ? FontAwesome.OUTDENT.getHtml() + "&nbsp&nbsp:&nbsp&nbsp" + item.getValidFromGmt()
                : "&nbsp|" + FontAwesome.OUTDENT.getHtml() + "&nbsp&nbsp:&nbsp&nbsp" + item.getValidFromGmt();
    }

    if (!StringUtils.isNullOrEmpty(item.getValidToGmt())) {
        info += StringUtils.isNullOrEmpty(info)
                ? FontAwesome.OUTDENT.getHtml() + "&nbsp&nbsp:&nbsp&nbsp" + item.getValidToGmt()
                : "&nbsp|" + FontAwesome.OUTDENT.getHtml() + "&nbsp&nbsp:&nbsp&nbsp" + item.getValidToGmt();
    }

    if (!StringUtils.isNullOrEmpty(info)) {
        lbInfo.setCaption(info);
    }

    btnEdit.addClickListener((Button.ClickEvent event) -> {
        if (item != null) {
            SlideShowInsert slideShowInsert = new SlideShowInsert(item//
            , event.getButton().findAncestor(SlideShowView.class)//
            , Constants.ACTION.UPDATE);
            slideShowInsert.setWidth("80%");
            slideShowInsert.setHeight("90%");
            slideShowInsert.setModal(true);
            FWUtils.reloadWindow(slideShowInsert);
            UI.getCurrent().addWindow(slideShowInsert);
        }
    });

    btnDelete.addClickListener((Button.ClickEvent event) -> {
        ConfirmDialog.show(UI.getCurrent(), BundleUtils.getLanguage("lbl.confirm")//
        , BundleUtils.getLanguage("message.category.delete.confirm")//
        , BundleUtils.getLanguage("lbl.yes")//
        , BundleUtils.getLanguage("lbl.no")//
        , (ConfirmDialog cd) -> {
            if (cd.isConfirmed()) {
                UserDTO user = (UserDTO) VaadinSession.getCurrent().getAttribute(UserDTO.class.getName());
                ResultDTO result = ClientServiceImpl.getInstance().deleteSlideShow(user.getUsername()//
                , getLocale().getLanguage(), getLocale().getCountry(), null, Long.valueOf(itemId));
                if (result != null && Constants.SUCCESS.equals(result.getMessage())) {
                    mainView.onSearch(Boolean.TRUE);
                    UI.getCurrent().removeWindow(event.getButton().findAncestor(Window.class));
                } else {
                    Notification.show(
                            result == null || result.getKey() == null ? Constants.FAIL : result.getKey(),
                            Notification.Type.ERROR_MESSAGE);
                }
            }
        });
    });

}

From source file:com.dungnv.streetfood.view.ArticleInsert.java

public ArticleInsert(ArticleDTO dto, ArticleView view, Constants.ACTION action) {

    setLocale(VaadinSession.getCurrent().getLocale());
    if (dto != null && !StringUtils.isNullOrEmpty(dto.getId())) {
        UserDTO user = (UserDTO) VaadinSession.getCurrent().getAttribute(UserDTO.class.getName());
        dto = ClientServiceImpl.getInstance().getArticleDetail(user.getUsername()//
                , getLocale().getLanguage(), getLocale().getCountry(), null, dto.getId());
    } else {//from   www.j av a2s.  c o  m
        dto = null;
    }

    this.dto = dto == null ? new ArticleDTO() : dto;
    this.view = view;
    this.action = action;
    init();
    setContent(layout);
}

From source file:com.dungnv.streetfood.view.ArticleInsert.java

@Override
public void wizardCompleted(WizardCompletedEvent event) {
    UserDTO user = (UserDTO) VaadinSession.getCurrent().getAttribute(UserDTO.class.getName());
    ResultDTO result = null;//w  w w. ja v  a 2 s .com
    if (null != action) {
        switch (action) {
        case INSERT:
            result = ClientServiceImpl.getInstance().insertArticle(user.getUsername()//
                    , getLocale().getLanguage(), getLocale().getCountry(), null, dto);
            break;
        case UPDATE:
            result = ClientServiceImpl.getInstance().updateArticle(user.getUsername()//
                    , getLocale().getLanguage(), getLocale().getCountry(), null, dto);
            break;
        default:
            UI.getCurrent().removeWindow(event.getWizard().findAncestor(Window.class));
            return;
        }
    }

    if (result != null && Constants.SUCCESS.equals(result.getMessage())) {
        view.onSearch(Boolean.TRUE);
        UI.getCurrent().removeWindow(event.getWizard().findAncestor(Window.class));
    } else {
        Notification.show(result == null || result.getKey() == null ? Constants.FAIL : result.getKey(),
                Notification.Type.ERROR_MESSAGE);
    }
}

From source file:com.dungnv.streetfood.view.ArticleLink.java

private void init() {

    setLocale(VaadinSession.getCurrent().getLocale());

    VerticalLayout vLayout = new VerticalLayout();

    tabSheet = new TabSheet();
    tabSheet.setStyleName(ValoTheme.TABSHEET_EQUAL_WIDTH_TABS);
    tabSheet.setSizeFull();//w w w .j  a  va2 s  . co m
    vLayout.addComponent(tabSheet);

    // DishArticle
    tuiDish = new TwinColumnUI("name");
    tuiDish.setLeftLabelCaption(BundleUtils.getLanguage("lbl.dish.avaiable.list"));
    tuiDish.setRightLabelCaption(BundleUtils.getLanguage("lbl.dish.selected.list"));
    tabSheet.addTab(tuiDish, BundleUtils.getLanguage("lbl.article.dishArticle.tab"));

    // RestaurantArticle
    tuiRestaurant = new TwinColumnUI("name");
    tuiRestaurant.setLeftLabelCaption(BundleUtils.getLanguage("lbl.restaurant.avaiable.list"));
    tuiRestaurant.setRightLabelCaption(BundleUtils.getLanguage("lbl.restaurant.selected.list"));
    tabSheet.addTab(tuiRestaurant, BundleUtils.getLanguage("lbl.article.restaurantArticle.tab"));

    setContent(tabSheet);
}