Example usage for com.vaadin.server VaadinRequest getService

List of usage examples for com.vaadin.server VaadinRequest getService

Introduction

In this page you can find the example usage for com.vaadin.server VaadinRequest getService.

Prototype

public VaadinService getService();

Source Link

Document

Gets the vaadin service for the context of this request.

Usage

From source file:org.sensorhub.ui.AdminUI.java

License:Mozilla Public License

@Override
protected void init(VaadinRequest request) {
    String configClass = null;//w  w  w.j  a  va 2s  . c om
    moduleConfigLists.clear();

    // retrieve module config
    try {
        Properties initParams = request.getService().getDeploymentConfiguration().getInitParameters();
        String moduleID = initParams.getProperty(AdminUIModule.SERVLET_PARAM_MODULE_ID);
        uiConfig = (AdminUIConfig) SensorHub.getInstance().getModuleRegistry().getModuleById(moduleID)
                .getConfiguration();
    } catch (Exception e) {
        throw new RuntimeException("Cannot get UI module configuration", e);
    }

    try {
        // load default form builders
        customForms.put(HttpServerConfig.class.getCanonicalName(), HttpServerConfigForm.class);
        customForms.put(StreamStorageConfig.class.getCanonicalName(), GenericStorageConfigForm.class);
        customForms.put(CommConfig.class.getCanonicalName(), CommConfigForm.class);
        customForms.put(SOSConfigForm.SOS_PACKAGE + "SOSServiceConfig", SOSConfigForm.class);
        customForms.put(SOSConfigForm.SOS_PACKAGE + "SOSProviderConfig", SOSConfigForm.class);

        // load custom form builders defined in config
        for (CustomUIConfig customForm : uiConfig.customForms) {
            configClass = customForm.configClass;
            Class<?> clazz = Class.forName(customForm.uiClass);
            customForms.put(configClass, (Class<IModuleConfigForm>) clazz);
            log.debug("Loaded custom form for " + configClass);
        }
    } catch (Exception e) {
        log.error("Error while instantiating form builder for config class " + configClass, e);
    }

    try {
        // load default panel builders
        customPanels.put(SensorConfig.class.getCanonicalName(), SensorAdminPanel.class);
        customPanels.put(StorageConfig.class.getCanonicalName(), StorageAdminPanel.class);

        // load custom panel builders defined in config
        for (CustomUIConfig customPanel : uiConfig.customPanels) {
            configClass = customPanel.configClass;
            Class<?> clazz = Class.forName(customPanel.uiClass);
            customPanels.put(configClass, (Class<IModuleAdminPanel<?>>) clazz);
            log.debug("Loaded custom panel for " + configClass);
        }
    } catch (Exception e) {
        log.error("Error while instantiating panel builder for config class " + configClass, e);
    }

    // register new field converter for interger numbers
    @SuppressWarnings("serial")
    ConverterFactory converterFactory = new DefaultConverterFactory() {
        @Override
        protected <PRESENTATION, MODEL> Converter<PRESENTATION, MODEL> findConverter(
                Class<PRESENTATION> presentationType, Class<MODEL> modelType) {
            // Handle String <-> Integer/Short/Long
            if (presentationType == String.class
                    && (modelType == Long.class || modelType == Integer.class || modelType == Short.class)) {
                return (Converter<PRESENTATION, MODEL>) new StringToIntegerConverter() {
                    @Override
                    protected NumberFormat getFormat(Locale locale) {
                        NumberFormat format = super.getFormat(Locale.US);
                        format.setGroupingUsed(false);
                        return format;
                    }
                };
            }
            // Let default factory handle the rest
            return super.findConverter(presentationType, modelType);
        }
    };
    VaadinSession.getCurrent().setConverterFactory(converterFactory);

    // init main panels
    HorizontalSplitPanel splitPanel = new HorizontalSplitPanel();
    splitPanel.setMinSplitPosition(300.0f, Unit.PIXELS);
    splitPanel.setMaxSplitPosition(30.0f, Unit.PERCENTAGE);
    splitPanel.setSplitPosition(350.0f, Unit.PIXELS);
    setContent(splitPanel);

    // build left pane
    VerticalLayout leftPane = new VerticalLayout();
    leftPane.setSizeFull();

    // header image and title
    Component header = buildHeader();
    leftPane.addComponent(header);
    leftPane.setExpandRatio(header, 0);

    // toolbar
    Component toolbar = buildToolbar();
    leftPane.addComponent(toolbar);
    leftPane.setExpandRatio(toolbar, 0);

    // accordion with several sections
    Accordion stack = new Accordion();
    stack.setSizeFull();
    VerticalLayout layout;
    Tab tab;

    layout = new VerticalLayout();
    tab = stack.addTab(layout, "Sensors");
    tab.setIcon(ACC_TAB_ICON);
    buildModuleList(layout, SensorConfig.class);

    layout = new VerticalLayout();
    tab = stack.addTab(layout, "Storage");
    tab.setIcon(ACC_TAB_ICON);
    buildModuleList(layout, StorageConfig.class);

    layout = new VerticalLayout();
    tab = stack.addTab(layout, "Processing");
    tab.setIcon(ACC_TAB_ICON);
    buildModuleList(layout, ProcessConfig.class);

    layout = new VerticalLayout();
    tab = stack.addTab(layout, "Services");
    tab.setIcon(ACC_TAB_ICON);
    buildModuleList(layout, ServiceConfig.class);

    layout = new VerticalLayout();
    tab = stack.addTab(layout, "Clients");
    tab.setIcon(ACC_TAB_ICON);
    buildModuleList(layout, ClientConfig.class);

    layout = new VerticalLayout();
    tab = stack.addTab(layout, "Network");
    tab.setIcon(ACC_TAB_ICON);
    buildNetworkConfig(layout);

    leftPane.addComponent(stack);
    leftPane.setExpandRatio(stack, 1);
    splitPanel.addComponent(leftPane);

    // init config area
    configArea = new VerticalLayout();
    configArea.setMargin(true);
    splitPanel.addComponent(configArea);
}

From source file:org.vaadin.spring.security.internal.SecurityContextVaadinRequestListener.java

License:Apache License

@Override
public void onRequestStart(VaadinRequest request, VaadinResponse response) {
    final WrappedSession wrappedSession = request.getWrappedSession(false);
    VaadinSession session = null;//from   w  ww  .j a  v  a  2 s  .c o  m
    if (wrappedSession != null) {
        session = VaadinSession.getForSession(request.getService(), wrappedSession);
    }

    SecurityContextHolder.clearContext();
    if (session != null) {
        logger.debug("Loading security context from VaadinSession {}", session);
        SecurityContext securityContext;
        session.lock();
        try {
            securityContext = (SecurityContext) session.getAttribute(SECURITY_CONTEXT_SESSION_ATTRIBUTE);
        } finally {
            session.unlock();
        }
        if (securityContext == null) {
            logger.debug("No security context found in VaadinSession {}", session);
        } else {
            logger.debug("Setting security context to {}", securityContext);
            SecurityContextHolder.setContext(securityContext);
        }
    } else {
        logger.debug("No VaadinSession available for retrieving the security context");
    }
}

From source file:org.vaadin.spring.security.managed.SecurityContextVaadinRequestListener.java

License:Apache License

@Override
public void onRequestStart(VaadinRequest request, VaadinResponse response) {
    final WrappedSession wrappedSession = request.getWrappedSession(false);
    VaadinSession session = null;/*w  w w .j a  v a 2 s. c  o  m*/
    if (wrappedSession != null) {
        session = VaadinSession.getForSession(request.getService(), wrappedSession);
    }

    SecurityContextHolder.clearContext();
    if (session != null) {
        logger.trace("Loading security context from VaadinSession {}", session);
        SecurityContext securityContext;
        session.lock();
        try {
            securityContext = (SecurityContext) session.getAttribute(SECURITY_CONTEXT_SESSION_ATTRIBUTE);
        } finally {
            session.unlock();
        }
        if (securityContext == null) {
            logger.trace("No security context found in VaadinSession {}", session);
        } else {
            logger.trace("Setting security context to {}", securityContext);
            SecurityContextHolder.setContext(securityContext);
        }
    } else {
        logger.trace("No VaadinSession available for retrieving the security context");
    }
}

From source file:org.vaadin.tori.ToriApiLoader.java

License:Apache License

public static void init(final VaadinRequest request) {
    ToriApiLoader toriApiLoader = VaadinSession.getCurrent().getAttribute(ToriApiLoader.class);
    if (toriApiLoader == null) {
        toriApiLoader = new ToriApiLoader();
        toriApiLoader.toriMailService = toriApiLoader.createToriMailService(request);
        if (toriApiLoader.getToriActivityMessaging() != null) {
            toriApiLoader.getToriActivityMessaging().register();
        }/*w ww  .  j a v  a2  s.  c o  m*/
        request.getService().addSessionDestroyListener(toriApiLoader);
        VaadinSession.getCurrent().setAttribute(ToriApiLoader.class, toriApiLoader);
    }
    toriApiLoader.sessionId = VaadinSession.getCurrent().getSession().getId();
    toriApiLoader.setRequest(request);
}

From source file:pl.exsio.frameset.vaadin.bootstrap.vaadin.ui.provider.FramesetUIProvider.java

License:Open Source License

protected String getUIBeanName(VaadinRequest request) {
    String vaadinBeanName = "ui";

    Object uiBeanName = request.getService().getDeploymentConfiguration()
            .getApplicationOrSystemProperty(BEAN_NAME_PARAMETER, null);
    if (uiBeanName != null && uiBeanName instanceof String) {
        vaadinBeanName = uiBeanName.toString();
    }//from  w  w w .j  a  va 2  s  .c  o m

    return vaadinBeanName;
}