Example usage for com.vaadin.server VaadinService getCurrentRequest

List of usage examples for com.vaadin.server VaadinService getCurrentRequest

Introduction

In this page you can find the example usage for com.vaadin.server VaadinService getCurrentRequest.

Prototype

public static VaadinRequest getCurrentRequest() 

Source Link

Document

Gets the currently processed Vaadin request.

Usage

From source file:nl.kpmg.lcm.ui.rest.RestClientService.java

License:Apache License

private void saveLoginUser(String loginUser) {
    VaadinService.getCurrentRequest().getWrappedSession().setAttribute("loginUser", loginUser);
}

From source file:nl.kpmg.lcm.ui.rest.RestClientService.java

License:Apache License

private void clearLoginToken() {
    VaadinService.getCurrentRequest().getWrappedSession().removeAttribute("loginToken");
}

From source file:nl.kpmg.lcm.ui.rest.RestClientService.java

License:Apache License

private void clearLoginUser() {
    VaadinService.getCurrentRequest().getWrappedSession().removeAttribute("loginUser");
}

From source file:nl.kpmg.lcm.ui.rest.RestClientService.java

License:Apache License

private String retrieveLoginToken() {
    WrappedSession wrappedSession = VaadinService.getCurrentRequest().getWrappedSession();
    return (String) wrappedSession.getAttribute("loginToken");
}

From source file:nl.kpmg.lcm.ui.rest.RestClientService.java

License:Apache License

private String retrieveLoginUser() {
    WrappedSession wrappedSession = VaadinService.getCurrentRequest().getWrappedSession();
    return (String) wrappedSession.getAttribute("loginUser");
}

From source file:org.agocontrol.site.AgoControlSiteUI.java

License:Apache License

@Override
protected Site constructSite(final VaadinRequest request) {
    final ContentProvider contentProvider = this;

    final LocalizationProvider localizationProvider = new LocalizationProviderBundleImpl(
            new String[] { "bare-site-localization", "ago-control-vaadin-site-localization" });

    BareSiteFields.initialize(localizationProvider, getLocale());
    AgoControlSiteFields.initialize(localizationProvider, getLocale());

    final SiteContext siteContext = new SiteContext();
    final EntityManager entityManager = entityManagerFactory.createEntityManager();
    siteContext.putObject(EntityManagerFactory.class, entityManagerFactory);
    siteContext.putObject(EntityManager.class, entityManager);

    Company company = CompanyDao.getCompany(entityManager,
            ((VaadinServletRequest) VaadinService.getCurrentRequest()).getHttpServletRequest().getServerName());
    if (company == null) {
        // If no exact host match exists then try to find global company marked with *.
        company = CompanyDao.getCompany(entityManager, "*");
    }/*  ww w .  j  a v a  2 s .  c  o m*/
    siteContext.putObject(Company.class, company);

    final SecurityProviderSessionImpl securityProvider = new SecurityProviderSessionImpl(
            Arrays.asList("administrator", "user"));

    return new Site(SiteMode.PRODUCTION, contentProvider, localizationProvider, securityProvider, siteContext);
}

From source file:org.apache.usergrid.chop.webapp.view.main.MainView.java

License:Apache License

private void redirectToMainView() {
    // Close the VaadinServiceSession
    getUI().getSession().close();//  ww  w . j  a v  a  2 s.c  om

    // Invalidate underlying session instead if login info is stored there
    VaadinService.getCurrentRequest().getWrappedSession().invalidate();
    getUI().getPage().setLocation("/VAADIN");
}

From source file:org.azrul.langkuik.Langkuik.java

public void initLangkuik(final EntityManagerFactory emf, final UI ui,
        final RelationManagerFactory relationManagerFactory, List<Class<?>> customTypeInterfaces) {

    List<Class<?>> rootClasses = new ArrayList<>();
    for (ManagedType<?> entity : emf.getMetamodel().getManagedTypes()) {
        Class<?> clazz = entity.getJavaType();
        if (clazz.getAnnotation(WebEntity.class).isRoot() == true) {
            rootClasses.add(clazz);/*from   www.jav  a 2s  .  co m*/
        }
    }

    //Manage custom type
    if (customTypeInterfaces == null) {
        customTypeInterfaces = new ArrayList<>();
    }
    //add system level custom type
    customTypeInterfaces.add(AttachmentCustomType.class);
    //create DAOs for custom types
    final List<DataAccessObject<?>> customTypeDaos = new ArrayList<>();
    for (Class<?> clazz : customTypeInterfaces) {
        customTypeDaos.add(new HibernateGenericDAO(emf, clazz));
    }

    //Setup page
    VerticalLayout main = new VerticalLayout();
    VerticalLayout content = new VerticalLayout();
    final Navigator navigator = new Navigator(ui, content);
    final HorizontalLayout breadcrumb = new HorizontalLayout();

    MenuBar menubar = new MenuBar();
    menubar.setId("MENUBAR");
    main.addComponent(menubar);
    main.addComponent(breadcrumb);
    main.addComponent(content);

    final Deque<History> history = new ArrayDeque<>();
    final Configuration config = Configuration.getInstance();

    history.push(new History("START", "Start"));
    StartView startView = new StartView(history, breadcrumb);
    navigator.addView("START", startView);
    MenuBar.MenuItem create = menubar.addItem("Create", null);
    MenuBar.MenuItem view = menubar.addItem("View", null);

    final PageParameter pageParameter = new PageParameter(customTypeDaos, emf, relationManagerFactory, history,
            config, breadcrumb);

    for (final Class rootClass : rootClasses) {
        final WebEntity myObject = (WebEntity) rootClass.getAnnotation(WebEntity.class);
        final DataAccessObject<?> dao = new HibernateGenericDAO<>(emf, rootClass);
        create.addItem("New " + myObject.name(), new MenuBar.Command() {
            @Override
            public void menuSelected(MenuBar.MenuItem selectedItem) {
                Object object = dao.createNew(true);
                BeanView<Object, ?> createNewView = new BeanView<>(object, null, null, pageParameter);
                String targetView = "CREATE_NEW_APPLICATION_" + UUID.randomUUID().toString();
                navigator.addView(targetView, (View) createNewView);
                history.clear();
                history.push(new History("START", "Start"));
                History his = new History(targetView, "Create new " + myObject.name());
                history.push(his);
                navigator.navigateTo(targetView);
            }
        });
        view.addItem("View " + myObject.name(), new MenuBar.Command() {
            @Override
            public void menuSelected(MenuBar.MenuItem selectedItem) {
                PlainTableView<?> seeApplicationView = new PlainTableView<>(rootClass, pageParameter);
                String targetView = "VIEW_APPLICATION_" + UUID.randomUUID().toString();
                navigator.addView(targetView, (View) seeApplicationView);
                history.clear();
                history.push(new History("START", "Start"));
                History his = new History(targetView, "View " + myObject.name());
                history.push(his);
                navigator.navigateTo(targetView);
            }
        });
    }

    menubar.addItem("Logout", null).addItem("Logout", new MenuBar.Command() {
        @Override
        public void menuSelected(MenuBar.MenuItem selectedItem) {
            ConfirmDialog.show(ui, "Please Confirm:", "Are you really sure you want to log out?", "I am",
                    "Not quite", new ConfirmDialog.Listener() {
                        @Override
                        public void onClose(ConfirmDialog dialog) {
                            if (dialog.isConfirmed()) {
                                HttpServletRequest req = (HttpServletRequest) VaadinService.getCurrentRequest();
                                HttpServletResponse resp = (HttpServletResponse) VaadinService
                                        .getCurrentResponse();
                                Authentication auth = SecurityContextHolder.getContext().getAuthentication();
                                SecurityContextLogoutHandler ctxLogOut = new SecurityContextLogoutHandler();
                                ctxLogOut.logout(req, resp, auth);
                            }
                        }
                    });

        }
    });
    navigator.navigateTo("START");
    ui.setContent(main);
}

From source file:org.bubblecloud.ilves.comment.CommentAddComponent.java

License:Open Source License

/**
 * The default constructor which instantiates Vaadin
 * component hierarchy.// www .j a  v  a2 s. c  o  m
 */
public CommentAddComponent() {

    final User user = DefaultSiteUI.getSecurityProvider().getUserFromSession();

    final String contextPath = VaadinService.getCurrentRequest().getContextPath();
    final Site site = Site.getCurrent();

    final Company company = site.getSiteContext().getObject(Company.class);
    final EntityManager entityManager = site.getSiteContext().getObject(EntityManager.class);

    final Panel panel = new Panel(site.localize("panel-add-comment"));
    setCompositionRoot(panel);

    final VerticalLayout mainLayout = new VerticalLayout();
    panel.setContent(mainLayout);
    mainLayout.setMargin(true);
    mainLayout.setSpacing(true);

    final TextArea commentMessageField = new TextArea(site.localize("field-comment-message"));
    mainLayout.addComponent(commentMessageField);
    commentMessageField.setWidth(100, Unit.PERCENTAGE);
    commentMessageField.setRows(3);
    commentMessageField.setMaxLength(255);

    final Button addCommentButton = new Button(site.localize("button-add-comment"));
    mainLayout.addComponent(addCommentButton);
    if (user == null) {
        commentMessageField.setEnabled(false);
        commentMessageField.setInputPrompt(site.localize("message-please-login-to-comment"));
        addCommentButton.setEnabled(false);
    }

    addCommentButton.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            final String commentMessage = commentMessageField.getValue();
            if (StringUtils.isEmpty(commentMessage)) {
                return;
            }
            final Comment comment = new Comment(company, user, contextPath, commentMessage);
            entityManager.getTransaction().begin();
            try {
                entityManager.persist(comment);
                entityManager.getTransaction().commit();
                commentMessageField.setValue("");
                if (commentListComponent != null) {
                    commentListComponent.refresh();
                }
            } finally {
                if (entityManager.getTransaction().isActive()) {
                    entityManager.getTransaction().rollback();
                }
            }
        }
    });

}

From source file:org.bubblecloud.ilves.comment.CommentListComponent.java

License:Open Source License

public void refresh() {

    final String contextPath = VaadinService.getCurrentRequest().getContextPath();
    final Site site = Site.getCurrent();

    final Company company = site.getSiteContext().getObject(Company.class);
    final EntityManager entityManager = site.getSiteContext().getObject(EntityManager.class);

    final CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    final CriteriaQuery<Comment> commentCriteriaQuery = builder.createQuery(Comment.class);
    final Root<Comment> commentRoot = commentCriteriaQuery.from(Comment.class);
    commentCriteriaQuery.where(builder.and(builder.equal(commentRoot.get("owner"), company),
            builder.equal(commentRoot.get("dataId"), contextPath)));
    commentCriteriaQuery.orderBy(builder.asc(commentRoot.get("created")));

    final TypedQuery<Comment> commentTypedQuery = entityManager.createQuery(commentCriteriaQuery);
    final List<Comment> commentList = commentTypedQuery.getResultList();

    final Panel panel = new Panel(site.localize("panel-comments"));
    setCompositionRoot(panel);/*from   w  ww  . j  a  v a2s .c om*/

    final GridLayout gridLayout = new GridLayout(3, commentList.size() + 1);
    panel.setContent(gridLayout);
    gridLayout.setSpacing(true);
    gridLayout.setMargin(true);
    gridLayout.setColumnExpandRatio(0, 0.0f);
    gridLayout.setColumnExpandRatio(1, 0.1f);
    gridLayout.setColumnExpandRatio(2, 0.9f);

    final Label authorHeaderLabel = new Label();
    authorHeaderLabel.setStyleName(ValoTheme.LABEL_BOLD);
    authorHeaderLabel.setValue(site.localize("column-header-author"));
    gridLayout.addComponent(authorHeaderLabel, 0, 0, 1, 0);

    final Label commentHeaderLabel = new Label();
    commentHeaderLabel.setStyleName(ValoTheme.LABEL_BOLD);
    commentHeaderLabel.setValue(site.localize("column-header-comment"));
    gridLayout.addComponent(commentHeaderLabel, 2, 0);

    for (int i = 0; i < commentList.size(); i++) {
        final Comment comment = commentList.get(i);

        final Link authorImageLink = GravatarUtil.getGravatarImageLink(comment.getAuthor().getEmailAddress());
        gridLayout.addComponent(authorImageLink, 0, i + 1);

        final Label authorLabel = new Label();
        final String authorName = comment.getAuthor().getFirstName();
        authorLabel.setValue(authorName);
        gridLayout.addComponent(authorLabel, 1, i + 1);

        final Label messageLabel = new Label();
        messageLabel.setValue(comment.getMessage());
        gridLayout.addComponent(messageLabel, 2, i + 1);
    }

}