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:process.control.LoginControl.java

public static void logoutuser() {
    UI.getCurrent().getPage().setLocation("/SE2Projekt");
    VaadinSession.getCurrent().close();

}

From source file:ui.button.LogoutButton.java

License:Apache License

@Override
public void buttonClick(ClickEvent event) {
    VaadinSession.getCurrent().close();
    VaadinSession.getCurrent().getSession().invalidate();
    String path = VaadinService.getCurrentRequest().getContextPath();
    Page.getCurrent().setLocation(path);
    String msg = Translator.getTranslation("Loging out...", language);
    Notification.show(msg, Notification.Type.TRAY_NOTIFICATION);
    UI.getCurrent().close();//  www.  ja v  a 2s.c om
}

From source file:uk.q3c.krail.core.guice.vsscope.VaadinSessionScopeProvider.java

License:Apache License

@Override
public T get() {/*from   www. j  a v a2s.com*/
    // get the scope cache for the current UI
    log.debug("looking for a VaadinSessionScoped instance of {}", key.getClass().getName());

    // get the current VaadinSession
    VaadinSession vaadinSession = VaadinSession.getCurrent();

    log.debug("looking for cache for key in current VaadinSession ");
    Map<Key<?>, Object> scopedObjects = this.vaadinSessionScope.getScopedObjectMap(vaadinSession);

    // retrieve an existing instance if possible

    @SuppressWarnings("unchecked")
    T current = (T) scopedObjects.get(key);

    if (current != null) {
        log.debug("returning existing instance of " + current.getClass().getSimpleName());
        return current;
    }

    // or create the first instance and cache it
    current = unscoped.get();
    scopedObjects.put(key, current);
    log.debug("new instance of {} created, as none in cache", current.getClass().getSimpleName());
    return current;
}

From source file:uk.q3c.krail.core.shiro.DefaultSubjectProvider.java

License:Apache License

/**
 * Returns the subject for the application and thread which represents the
 * current user. The subject is always available; however it may represent an
 * anonymous user.// w ww.j a va  2 s. c o m
 *
 * @return the subject for the current application and thread
 *
 * @see SecurityUtils#getSubject()
 */
public Subject getSubject() {
    VaadinSession session = VaadinSession.getCurrent();

    // This should never happen, but just in case we'll check.
    if (session == null) {
        throw new IllegalStateException("Unable to locate VaadinSession " + "to store Shiro Subject.");
    }

    Subject subject = (Subject) session.getAttribute(SUBJECT_ATTRIBUTE);

    if (subject == null) {

        // Create a new subject using the configured security manager.
        subject = (new Subject.Builder(securityManager)).buildSubject();
        session.setAttribute(SUBJECT_ATTRIBUTE, subject);
    }
    return subject;
}

From source file:uk.q3c.krail.core.shiro.DefaultVaadinSessionProvider.java

License:Apache License

@Override
public VaadinSession get() {
    VaadinSession session = VaadinSession.getCurrent();

    // This may happen in background threads, or testing
    if (session == null) {
        String msg = "Vaadin session not present.  If you are testing, use a Mock for this provider";
        log.warn(msg);/*from ww  w. j a  va  2  s.  com*/
        throw new IllegalStateException(msg);
    }

    return session;
}

From source file:views.WorkflowView.java

License:Open Source License

private void updateParameterView(Workflow workFlow, BeanItemContainer<DatasetBean> projectDatasets) {
    this.submission.setCaption(SUBMISSION_CAPTION + ": " + workFlow.getName());
    this.submission.removeAllComponents();
    if (workFlow.getName().equals("MaxQuant")) {
        BeanItemContainer<RawFilesBean> rawFilesBeans = new BeanItemContainer<RawFilesBean>(RawFilesBean.class);
        BeanItemContainer<FastaBean> selectedfastas = new BeanItemContainer<FastaBean>(FastaBean.class);
        BeanItemContainer<FastaBean> fastas = new BeanItemContainer<FastaBean>(FastaBean.class);
        FastaDB db = new FastaDB();
        fastas.addAll(db.getAll());/*from w  w w  .j ava2 s.  c  o  m*/

        MaxQuantModel model = new MaxQuantModel(rawFilesBeans, projectDatasets, selectedfastas, fastas);
        VaadinSession.getCurrent().setConverterFactory(new MaxquantConverterFactory());
        MaxQuantComponent maxquantComponent = new MaxQuantComponent(model, controller);
        maxquantComponent.setWorkflow(workFlow);
        maxquantComponent.addSubmissionListener(new MaxQuantSubmissionListener(maxquantComponent));

        this.submission.addComponent(maxquantComponent);
    } else {
        StandardWorkflowComponent standardComponent = new StandardWorkflowComponent(controller);
        standardComponent.update(workFlow, projectDatasets);
        standardComponent.addResetListener(new ResetListener(standardComponent));
        standardComponent.addSubmissionListener(new StandardSubmissionListener(standardComponent));
        this.submission.addComponent(standardComponent);
    }

}

From source file:xyz.iipster.security.VaadinSessionSecurityContextHolderStrategy.java

License:Apache License

/**
 * @return the current VaadinSession./*from  ww  w .j a v a2s .c om*/
 * @throws IllegalStateException if there is no VaadinSession.
 */
private static VaadinSession getSession() {
    VaadinSession session = VaadinSession.getCurrent();
    if (session == null) {
        throw new IllegalStateException("No VaadinSession bound to current thread");
    }
    return session;
}