CustomSpringUIProvider.java

  1. /*
  2.  * Copyright 2010-2025 James Pether Sörling
  3.  *
  4.  * Licensed under the Apache License, Version 2.0 (the "License");
  5.  * you may not use this file except in compliance with the License.
  6.  * You may obtain a copy of the License at
  7.  *
  8.  *   http://www.apache.org/licenses/LICENSE-2.0
  9.  *
  10.  * Unless required by applicable law or agreed to in writing, software
  11.  * distributed under the License is distributed on an "AS IS" BASIS,
  12.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13.  * See the License for the specific language governing permissions and
  14.  * limitations under the License.
  15.  *
  16.  *  $Id$
  17.  *  $HeadURL$
  18. */
  19. package com.hack23.cia.web.impl.ui.application;

  20. import com.vaadin.server.UICreateEvent;
  21. import com.vaadin.server.VaadinSession;
  22. import com.vaadin.spring.internal.SpringViewDisplayRegistrationBean;
  23. import com.vaadin.spring.internal.UIID;
  24. import com.vaadin.spring.server.SpringUIProvider;
  25. import com.vaadin.ui.UI;
  26. import com.vaadin.util.CurrentInstance;

  27. /**
  28.  * The Class CustomSpringUIProvider.
  29.  */
  30. public class CustomSpringUIProvider extends SpringUIProvider {

  31.     /** The Constant serialVersionUID. */
  32.     private static final long serialVersionUID = 1L;

  33.     /** The spring view display registration bean. */
  34.     private final SpringViewDisplayRegistrationBean springViewDisplayRegistrationBean = new SpringViewDisplayRegistrationBean();

  35.     /**
  36.      * Instantiates a new custom spring UI provider.
  37.      *
  38.      * @param vaadinSession the vaadin session
  39.      */
  40.     public CustomSpringUIProvider(final VaadinSession vaadinSession) {
  41.         super(vaadinSession);
  42.     }

  43.     @Override
  44.     public UI createInstance(final UICreateEvent event) {
  45.         final Class<UIID> key = UIID.class;
  46.         final UIID identifier = new UIID(event);
  47.         CurrentInstance.set(key, identifier);
  48.         try {
  49.             logger.debug("Creating a new UI bean of class [{}] with identifier [{}]",
  50.                     event.getUIClass().getCanonicalName(), identifier);
  51.             final UI ui = getWebApplicationContext().getBean(event.getUIClass());

  52.             getSpringViewDisplayRegistrationBean().setBeanClass(event.getUIClass());

  53.             configureNavigator(ui);
  54.             return ui;
  55.         } finally {
  56.             CurrentInstance.set(key, null);
  57.         }
  58.     }

  59.     @Override
  60.     protected Object findSpringViewDisplay(final UI ui) {
  61.         return getSpringViewDisplayRegistrationBean().getSpringViewDisplay(getWebApplicationContext());
  62.     }

  63.     /**
  64.      * Gets the spring view display registration bean.
  65.      *
  66.      * @return the spring view display registration bean
  67.      */
  68.     private SpringViewDisplayRegistrationBean getSpringViewDisplayRegistrationBean() {
  69.         return springViewDisplayRegistrationBean;

  70.     }
  71. }