Example usage for com.vaadin.server UICreateEvent getUIClass

List of usage examples for com.vaadin.server UICreateEvent getUIClass

Introduction

In this page you can find the example usage for com.vaadin.server UICreateEvent getUIClass.

Prototype

public Class<? extends UI> getUIClass() 

Source Link

Document

Gets the UI class that will be created.

Usage

From source file:com.google.code.vaadin.application.ui.ScopedUIProvider.java

License:Apache License

@Override
public UI createInstance(UICreateEvent event) {
    return createInstance(event.getUIClass());
}

From source file:de.appblocks.vaadin.cdi.TomcatCDIUIProvider.java

License:Apache License

@Override
public UI createInstance(UICreateEvent uiCreateEvent) {
    Class<? extends UI> type = uiCreateEvent.getUIClass();
    int uiId = uiCreateEvent.getUiId();
    VaadinRequest request = uiCreateEvent.getRequest();
    Bean<?> bean = scanForBeans(type);
    String uiMapping = "";
    if (bean == null) {
        if (type.isAnnotationPresent(CDIUI.class)) {
            uiMapping = parseUIMapping(request);
            bean = getUIBeanWithMapping(uiMapping);
        } else {//from www.ja  v a 2 s .c o m
            throw new IllegalStateException("UI class: " + type.getName() + " with mapping: " + uiMapping
                    + " is not annotated with CDIUI!");
        }
    }
    UIBean uiBean = new UIBean(bean, uiId);
    try {
        // Make the UIBean available to UIScopedContext when creating nested
        // injected objects
        CurrentInstance.set(UIBean.class, uiBean);
        return (UI) getBeanManager().getReference(uiBean, type, getBeanManager().createCreationalContext(bean));
    } finally {
        CurrentInstance.set(UIBean.class, null);
    }
}

From source file:fixture.UITestBase.java

License:Apache License

@SuppressWarnings("deprecation")
protected ScopedUI createUI(final Class<? extends ScopedUI> clazz) {
    CurrentInstance.set(UI.class, null);
    CurrentInstance.set(UIKey.class, null);
    UICreateEvent event = mock(UICreateEvent.class);
    // when(event.getSource()).thenReturn(vaadinService);

    Answer<Class<? extends ScopedUI>> answer = new Answer<Class<? extends ScopedUI>>() {

        @Override/*from  w w  w  . ja va 2  s  .c  o m*/
        public Class<? extends ScopedUI> answer(InvocationOnMock invocation) throws Throwable {
            return clazz;
        }
    };
    when(event.getUIClass()).thenAnswer(answer);
    ui = (ScopedUI) getUIProvider().createInstance(event);
    CurrentInstance.set(UI.class, ui);
    when(mockedRequest.getParameter("v-loc")).thenReturn(baseUri + "/");
    when(mockedSession.createConnectorId(Matchers.any(ClientConnector.class)))
            .thenAnswer(new ConnectorIdAnswer());
    ui.setSession(mockedSession);
    // ui.doInit(mockedRequest, 23);
    return ui;
}

From source file:org.simplewebstack.app.vaadin.guice.ui.ScopedUIProvider.java

License:Apache License

@Override
public UI createInstance(UICreateEvent event) {

    Class<? extends UI> uiClass = event.getUIClass();

    UIKey uiKey = uiKeyProvider.get();//from   www .  jav  a2s  . c o  m

    // hold the key while UI is created
    CurrentInstance.set(UIKey.class, uiKey);
    // and set up the scope
    UIScope scope = UIScope.getCurrent();

    scope.startScope(uiKey);

    // create the UI
    ScopedUI ui = (ScopedUI) injector.getInstance(uiClass);
    ui.setInstanceKey(uiKey);
    ui.setScope(scope);

    logger.debug(String.format("Returning instance of [%s] with key [%s]", uiClass.getName(), uiKey));
    return ui;
}

From source file:org.vaadin.spring.servlet.internal.AbstractSpringAwareUIProvider.java

License:Apache License

@Override
public UI createInstance(UICreateEvent event) {
    final Class<UIID> key = UIID.class;
    final UIID identifier = new UIID(event);
    CurrentInstance.set(key, identifier);
    try {/*from  w w w  .jav a2s. c  o  m*/
        logger.debug("Creating a new UI bean of class [{}] with identifier [{}]",
                event.getUIClass().getCanonicalName(), identifier);
        return webApplicationContext.getBean(event.getUIClass());
    } finally {
        CurrentInstance.set(key, null);
    }
}

From source file:org.vaadin.webinars.springandvaadin.i18n.ui.createTask.CreateTaskServlet.java

License:Apache License

@Override
protected void servletInitialized() throws ServletException {
    final ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
    getService().addSessionInitListener(new SessionInitListener() {
        @Override//from  ww  w .  j av  a 2s  . c o m
        public void sessionInit(SessionInitEvent sessionInitEvent) throws ServiceException {
            sessionInitEvent.getSession().addUIProvider(new UIProvider() {
                @Override
                public Class<? extends UI> getUIClass(UIClassSelectionEvent uiClassSelectionEvent) {
                    return CreateTaskUi.class;
                }

                @Override
                public UI createInstance(UICreateEvent event) {
                    return context.getBean(event.getUIClass());
                }
            });
        }
    });
}

From source file:org.vaadin.webinars.springandvaadin.i18n.ui.Servlet.java

License:Apache License

@Override
protected void servletInitialized() throws ServletException {
    final ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
    try {/*from  w w w.  j  av  a2s. c  om*/
        localeResolver = context.getBean(DispatcherServlet.LOCALE_RESOLVER_BEAN_NAME, LocaleResolver.class);
    } catch (NoSuchBeanDefinitionException e) {
        localeResolver = new SessionLocaleResolver();
    }
    getService().addSessionInitListener(new SessionInitListener() {
        @Override
        public void sessionInit(SessionInitEvent sessionInitEvent) throws ServiceException {
            sessionInitEvent.getSession().addUIProvider(new UIProvider() {
                @Override
                public Class<? extends UI> getUIClass(UIClassSelectionEvent uiClassSelectionEvent) {
                    return I18nUI.class;
                }

                @Override
                public UI createInstance(UICreateEvent event) {
                    return context.getBean(event.getUIClass());
                }
            });
        }
    });
}

From source file:uk.q3c.krail.core.ui.ScopedUIProvider.java

License:Apache License

@Override
public UI createInstance(UICreateEvent event) {
    Class<? extends UI> uiClass = event.getUIClass();
    UIKey uiKey = uiKeyProvider.get();/*from   ww  w  .j a va2s  . c  o  m*/
    // hold the key while UI is created
    CurrentInstance.set(UIKey.class, uiKey);
    // and set up the scope
    UIScope scope = UIScope.getCurrent();
    scope.startScope(uiKey);
    // create the UI
    ScopedUI ui = (ScopedUI) injector.getInstance(uiClass);
    ui.setInstanceKey(uiKey);
    ui.setScope(scope);

    log.debug("Returning instance of {} with key {}", uiClass.getName(), uiKey);
    return ui;
}