Revision 157460f4
Added by Andreas Kohlbecker about 7 years ago
src/main/java/com/vaadin/devday/ui/DevDayUI.java | ||
---|---|---|
5 | 5 |
|
6 | 6 |
import com.vaadin.annotations.Theme; |
7 | 7 |
import com.vaadin.annotations.Viewport; |
8 |
import com.vaadin.devday.ui.mainmenu.MenuBeanDiscoveryBean; |
|
9 | 8 |
import com.vaadin.navigator.ViewDisplay; |
10 | 9 |
import com.vaadin.server.Responsive; |
11 | 10 |
import com.vaadin.server.VaadinRequest; |
... | ... | |
31 | 30 |
/* |
32 | 31 |
* this HACKY solution forces the bean to be instantiated, TODO do it properly |
33 | 32 |
*/ |
34 |
@Autowired |
|
35 |
MenuBeanDiscoveryBean bean; |
|
33 |
// @Autowired
|
|
34 |
// MenuBeanDiscoveryBean bean;
|
|
36 | 35 |
|
37 | 36 |
@Override |
38 | 37 |
protected void init(VaadinRequest request) { |
... | ... | |
41 | 40 |
|
42 | 41 |
setContent((Component) viewDisplay); |
43 | 42 |
|
44 |
eventBus.publishEvent(new UIInitializedEvent()); |
|
43 |
//FIXME disabled! eventBus.publishEvent(new UIInitializedEvent());
|
|
45 | 44 |
} |
46 | 45 |
|
47 | 46 |
// @WebServlet(value = "/*", asyncSupported = true) |
src/main/java/com/vaadin/devday/ui/annotation/EnableVaadinSpringNavigation.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2017 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
* |
|
6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
8 |
*/ |
|
9 |
package com.vaadin.devday.ui.annotation; |
|
10 |
|
|
11 |
import java.lang.annotation.Documented; |
|
12 |
import java.lang.annotation.ElementType; |
|
13 |
import java.lang.annotation.Retention; |
|
14 |
import java.lang.annotation.RetentionPolicy; |
|
15 |
import java.lang.annotation.Target; |
|
16 |
|
|
17 |
import org.springframework.context.annotation.Configuration; |
|
18 |
import org.springframework.context.annotation.Import; |
|
19 |
|
|
20 |
import com.vaadin.devday.ui.config.VaadinSpringNavigatorConfiguration; |
|
21 |
import com.vaadin.devday.ui.navigation.NavigationManagerBean; |
|
22 |
import com.vaadin.spring.annotation.SpringViewDisplay; |
|
23 |
|
|
24 |
/** |
|
25 |
* Activates automatic navigation through the {@link NavigationManagerBean} based on |
|
26 |
* {@link SpringViewDisplay} annotations. This annotation should be added on a |
|
27 |
* {@link Configuration} class of the application to automatically import |
|
28 |
* {@link VaadinSpringNavigatorConfiguration}. |
|
29 |
* |
|
30 |
* @author a.kohlbecker |
|
31 |
* @since Feb 28, 2017 |
|
32 |
* |
|
33 |
*/ |
|
34 |
|
|
35 |
@Target(ElementType.TYPE) |
|
36 |
@Retention(RetentionPolicy.RUNTIME) |
|
37 |
@Documented |
|
38 |
@Import(VaadinSpringNavigatorConfiguration.class) |
|
39 |
public @interface EnableVaadinSpringNavigation { |
|
40 |
} |
src/main/java/com/vaadin/devday/ui/config/VaadinSpringNavigatorConfiguration.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2017 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
* |
|
6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
8 |
*/ |
|
9 |
package com.vaadin.devday.ui.config; |
|
10 |
|
|
11 |
import org.springframework.context.annotation.Bean; |
|
12 |
import org.springframework.context.annotation.Configuration; |
|
13 |
|
|
14 |
import com.vaadin.devday.ui.navigation.NavigationManagerBean; |
|
15 |
import com.vaadin.spring.annotation.UIScope; |
|
16 |
import com.vaadin.spring.internal.SpringViewDisplayPostProcessor; |
|
17 |
|
|
18 |
/** |
|
19 |
* @author a.kohlbecker |
|
20 |
* @since Feb 28, 2017 |
|
21 |
* |
|
22 |
*/ |
|
23 |
@Configuration |
|
24 |
public class VaadinSpringNavigatorConfiguration { |
|
25 |
|
|
26 |
@Bean //TODO see VaadinNavigatorConfiguration |
|
27 |
@UIScope |
|
28 |
public NavigationManagerBean vaadinNavigator() { |
|
29 |
return new NavigationManagerBean(); |
|
30 |
} |
|
31 |
|
|
32 |
@Bean //TODO see VaadinNavigatorConfiguration |
|
33 |
public static SpringViewDisplayPostProcessor springViewDisplayPostProcessor() { |
|
34 |
return new SpringViewDisplayPostProcessor(); |
|
35 |
} |
|
36 |
|
|
37 |
|
|
38 |
} |
src/main/java/com/vaadin/devday/ui/mainmenu/MenuBeanDiscoveryBean.java | ||
---|---|---|
14 | 14 |
import com.vaadin.devday.ui.MenuItem; |
15 | 15 |
import com.vaadin.devday.ui.UIInitializedEvent; |
16 | 16 |
import com.vaadin.navigator.View; |
17 |
import com.vaadin.spring.annotation.SpringComponent; |
|
18 | 17 |
import com.vaadin.spring.annotation.SpringView; |
19 |
import com.vaadin.spring.annotation.UIScope; |
|
20 | 18 |
|
19 |
// MenuBeanDiscovery is not yet working with spring!!!!! |
|
20 |
// |
|
21 | 21 |
// @NormalUIScoped // FIXME this provided a MenuBeanDiscoveryBean as a proxy, which is the equivalent in spring? |
22 | 22 |
// otherwise the following error will be thrown: |
23 | 23 |
// Error creating bean with name 'testView': Scope 'vaadin-view' is not active for the current thread; |
24 | 24 |
// consider defining a scoped proxy for this bean if you intend to refer to it from a singleton |
25 |
@SpringComponent
|
|
26 |
@UIScope
|
|
27 |
// @Scope(value=UIScopeImpl.VAADIN_UI_SCOPE_NAME, proxyMode = ScopedProxyMode.TARGET_CLASS)
|
|
25 |
//###DISABLED:
|
|
26 |
//@SpringComponent
|
|
27 |
//@UIScope
|
|
28 | 28 |
public class MenuBeanDiscoveryBean { |
29 | 29 |
|
30 | 30 |
@Autowired |
src/main/java/com/vaadin/devday/ui/navigation/NavigationManagerBean.java | ||
---|---|---|
5 | 5 |
|
6 | 6 |
import org.springframework.beans.factory.annotation.Autowired; |
7 | 7 |
import org.springframework.context.ApplicationEventPublisher; |
8 |
import org.springframework.context.annotation.Lazy; |
|
8 | 9 |
import org.springframework.context.event.EventListener; |
9 | 10 |
|
10 | 11 |
import com.vaadin.devday.ui.NavigationManager; |
... | ... | |
13 | 14 |
import com.vaadin.devday.ui.view.PopupView; |
14 | 15 |
import com.vaadin.navigator.ViewChangeListener; |
15 | 16 |
import com.vaadin.navigator.ViewDisplay; |
16 |
import com.vaadin.spring.annotation.SpringComponent; |
|
17 | 17 |
import com.vaadin.spring.annotation.UIScope; |
18 | 18 |
import com.vaadin.spring.navigator.SpringNavigator; |
19 | 19 |
import com.vaadin.spring.navigator.SpringViewProvider; |
20 | 20 |
import com.vaadin.ui.UI; |
21 | 21 |
import com.vaadin.ui.Window; |
22 | 22 |
|
23 |
@SpringComponent |
|
24 | 23 |
@UIScope |
25 |
class NavigationManagerBean extends SpringNavigator implements NavigationManager { |
|
24 |
public class NavigationManagerBean extends SpringNavigator implements NavigationManager {
|
|
26 | 25 |
|
27 | 26 |
private static final long serialVersionUID = 6599898650948333853L; |
28 | 27 |
|
... | ... | |
44 | 43 |
//@Autowired |
45 | 44 |
private Map<String, PopupView> popupViews = null; |
46 | 45 |
|
47 |
@Autowired |
|
46 |
/* |
|
47 |
* Why UriFragmentManager must be initialized lazily: |
|
48 |
* |
|
49 |
* when the SpringVaadinServlet usually is being instantiated the ServletUIInitHandler(UIInitHandler).getBrowserDetailsUI(VaadinRequest, VaadinSession) method is called which will |
|
50 |
* first cause the WebapplicationContext being created. Once this is done the initialization of the UI classes is completed. This means that the UI classes are not readily available |
|
51 |
* via Page.getCurrent() which is used in the UriFragmentManager constructor. The NavigationManagerBean is initialized with the WebapplicationContext, that is when the current ui is |
|
52 |
* not yet available, therefore the UriFragmentManager must be initialized lazily. |
|
53 |
*/ |
|
54 |
@Autowired |
|
55 |
@Lazy |
|
48 | 56 |
private UriFragmentManager uriFragmentManager; |
49 | 57 |
|
58 |
|
|
59 |
// public void setUriFragmentManager(UriFragmentManager uriFragmentManager) { |
|
60 |
// this.uriFragmentManager = uriFragmentManager; |
|
61 |
// } |
|
62 |
|
|
50 | 63 |
@Autowired |
51 | 64 |
ApplicationEventPublisher eventBus; |
52 | 65 |
|
src/main/java/eu/etaxonomy/cdm/addon/config/CdmVaadinConfiguration.java | ||
---|---|---|
14 | 14 |
import org.springframework.context.annotation.ComponentScan; |
15 | 15 |
import org.springframework.context.annotation.Configuration; |
16 | 16 |
|
17 |
import com.vaadin.devday.ui.annotation.EnableVaadinSpringNavigation; |
|
17 | 18 |
import com.vaadin.spring.annotation.EnableVaadin; |
18 | 19 |
import com.vaadin.spring.server.SpringVaadinServlet; |
19 | 20 |
|
... | ... | |
29 | 30 |
"com.vaadin.devday.ui" |
30 | 31 |
}) |
31 | 32 |
@EnableVaadin // this imports VaadinConfiguration |
33 |
@EnableVaadinSpringNavigation // activate the NavigationManagerBean |
|
32 | 34 |
public class CdmVaadinConfiguration { |
33 | 35 |
|
34 | 36 |
public static final Logger logger = Logger.getLogger(CdmVaadinConfiguration.class); |
35 | 37 |
|
36 |
|
|
37 | 38 |
/* |
38 | 39 |
* NOTE: It is necessary to map the URLs starting with /VAADIN/* since none of the |
39 | 40 |
* @WebServlets is mapped to the root path. It is sufficient to configure one of the |
src/main/java/eu/etaxonomy/cdm/vaadin/ui/RegistrationUI.java | ||
---|---|---|
15 | 15 |
import com.vaadin.annotations.Title; |
16 | 16 |
import com.vaadin.annotations.Viewport; |
17 | 17 |
import com.vaadin.annotations.Widgetset; |
18 |
import com.vaadin.devday.ui.MainMenu; |
|
18 | 19 |
import com.vaadin.devday.ui.UIInitializedEvent; |
19 | 20 |
import com.vaadin.navigator.ViewDisplay; |
21 |
import com.vaadin.server.FontAwesome; |
|
20 | 22 |
import com.vaadin.server.Responsive; |
21 | 23 |
import com.vaadin.server.VaadinRequest; |
22 | 24 |
import com.vaadin.spring.annotation.SpringUI; |
... | ... | |
24 | 26 |
import com.vaadin.ui.UI; |
25 | 27 |
import com.vaadin.ui.themes.ValoTheme; |
26 | 28 |
|
29 |
import eu.etaxonomy.cdm.vaadin.view.phycobank.TestView; |
|
30 |
|
|
27 | 31 |
/** |
28 | 32 |
* @author a.kohlbecker |
29 | 33 |
* @since Feb 24, 2017 |
... | ... | |
34 | 38 |
@SpringUI(path="registration") |
35 | 39 |
@Viewport("width=device-width, initial-scale=1") |
36 | 40 |
@Widgetset("eu.etaxonomy.cdm.vaadin.AppWidgetSet") |
37 |
@SuppressWarnings("serial") |
|
38 | 41 |
// @PreserveOnRefresh |
39 | 42 |
// @Push |
40 | 43 |
public class RegistrationUI extends UI { |
41 | 44 |
|
45 |
private static final long serialVersionUID = -8626236111335323691L; |
|
46 |
|
|
42 | 47 |
@Autowired |
43 | 48 |
private ViewDisplay viewDisplay; |
44 | 49 |
|
50 |
/* |
|
51 |
* this HACKY solution forces the bean to be instantiated, TODO do it properly |
|
52 |
*/ |
|
53 |
// @Autowired |
|
54 |
// MenuBeanDiscoveryBean bean; |
|
55 |
|
|
56 |
@Autowired |
|
57 |
private MainMenu mainMenu; |
|
58 |
|
|
45 | 59 |
@Autowired |
46 | 60 |
ApplicationEventPublisher eventBus; |
47 | 61 |
|
62 |
public RegistrationUI() { |
|
63 |
|
|
64 |
} |
|
65 |
|
|
48 | 66 |
@Override |
49 | 67 |
protected void init(VaadinRequest request) { |
50 | 68 |
addStyleName(ValoTheme.UI_WITH_MENU); |
... | ... | |
52 | 70 |
|
53 | 71 |
setContent((Component) viewDisplay); |
54 | 72 |
|
73 |
mainMenu.addMenuItem(TestView.NAME, FontAwesome.AMBULANCE, TestView.NAME); |
|
74 |
|
|
55 | 75 |
eventBus.publishEvent(new UIInitializedEvent()); |
56 | 76 |
} |
57 | 77 |
} |
src/main/java/eu/etaxonomy/cdm/vaadin/view/phycobank/TestView.java | ||
---|---|---|
10 | 10 |
|
11 | 11 |
import javax.annotation.PostConstruct; |
12 | 12 |
|
13 |
import org.springframework.context.annotation.Scope; |
|
14 |
import org.springframework.context.annotation.ScopedProxyMode; |
|
15 |
|
|
16 |
import com.vaadin.devday.ui.MenuItem; |
|
17 | 13 |
import com.vaadin.navigator.View; |
18 | 14 |
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent; |
19 |
import com.vaadin.server.FontAwesome; |
|
20 |
import com.vaadin.spring.annotation.SpringComponent; |
|
21 |
import com.vaadin.spring.internal.ViewScopeImpl; |
|
15 |
import com.vaadin.spring.annotation.SpringView; |
|
22 | 16 |
import com.vaadin.ui.Label; |
23 | 17 |
import com.vaadin.ui.VerticalLayout; |
24 | 18 |
|
... | ... | |
27 | 21 |
* @since Feb 24, 2017 |
28 | 22 |
* |
29 | 23 |
*/ |
30 |
//@SpringView |
|
24 |
@SpringView(name=TestView.NAME) |
|
25 |
/* |
|
26 |
* MenuBeanDiscovery is not yet working with spring!!!!! |
|
31 | 27 |
@SpringComponent |
32 | 28 |
@Scope(scopeName = ViewScopeImpl.VAADIN_VIEW_SCOPE_NAME, proxyMode = ScopedProxyMode.TARGET_CLASS) |
33 |
@MenuItem(name="Test", icon=FontAwesome.INFO_CIRCLE, order = 0) |
|
29 |
@MenuItem(name="test", icon=FontAwesome.INFO_CIRCLE, order = 0) |
|
30 |
*/ |
|
34 | 31 |
public class TestView extends VerticalLayout implements View { |
35 | 32 |
|
36 |
/** |
|
37 |
* |
|
38 |
*/ |
|
33 |
public static final String NAME = "test1"; |
|
34 |
|
|
39 | 35 |
private static final long serialVersionUID = 6152530138547633828L; |
40 | 36 |
|
41 | 37 |
public TestView(){ |
Also available in: Unified diff
working NavigationManagerBean, easier VaadinSpringNavigatorConfiguration, disabling MenuBeanDiscoveryBean