Project

General

Profile

« Previous | Next » 

Revision 43e0fe91

Added by Andreas Kohlbecker about 7 years ago

replacing Vaadin4Spring Event Bus by Spring ApplicationEventPublisher

View differences:

pom.xml
450 450
      <artifactId>contextmenu</artifactId>
451 451
      <version>4.5</version>
452 452
    </dependency>
453
    <dependency>
454
        <groupId>org.vaadin.spring.addons</groupId>
455
        <artifactId>vaadin-spring-addon-eventbus</artifactId>
456
        <version>0.0.7.RELEASE</version>
457
    </dependency>
458 453
    <!-- ============ cdmlib ============ -->
459 454
    <dependency>
460 455
      <groupId>eu.etaxonomy</groupId>
src/main/java/com/vaadin/devday/ui/DevDayUI.java
1 1
package com.vaadin.devday.ui;
2 2

  
3 3
import org.springframework.beans.factory.annotation.Autowired;
4
import org.vaadin.spring.events.EventBus;
4
import org.springframework.context.ApplicationEventPublisher;
5 5

  
6 6
import com.vaadin.annotations.Theme;
7 7
import com.vaadin.annotations.Viewport;
......
26 26
	private ViewDisplay viewDisplay;
27 27

  
28 28
	@Autowired
29
	private EventBus.UIEventBus eventBus;
29
	private ApplicationEventPublisher eventBus;
30 30

  
31 31
	/*
32 32
     * this HACKY solution forces the bean to be instantiated, TODO do it properly
......
41 41

  
42 42
		setContent((Component) viewDisplay);
43 43

  
44
		eventBus.publish(this, new UIInitializedEvent());
44
		eventBus.publishEvent(new UIInitializedEvent());
45 45
	}
46 46

  
47 47
	// @WebServlet(value = "/*", asyncSupported = true)
src/main/java/com/vaadin/devday/ui/mainmenu/MenuBeanDiscoveryBean.java
5 5
import java.util.Map;
6 6
import java.util.stream.Collectors;
7 7

  
8
import javax.annotation.PostConstruct;
9

  
10 8
import org.springframework.beans.factory.annotation.Autowired;
11 9
import org.springframework.context.ApplicationContext;
12
import org.vaadin.spring.events.EventBus;
13
import org.vaadin.spring.events.annotation.EventBusListenerMethod;
10
import org.springframework.context.ApplicationEventPublisher;
11
import org.springframework.context.event.EventListener;
14 12

  
15 13
import com.vaadin.devday.ui.MainMenu;
16 14
import com.vaadin.devday.ui.MenuItem;
......
33 31
	private ApplicationContext beanManager;
34 32

  
35 33
    @Autowired
36
    private EventBus.UIEventBus eventBus;
34
    private ApplicationEventPublisher eventBus;
37 35

  
38 36
	private MainMenu mainMenuLookup = null;
39 37

  
......
49 47
	    this.mainMenuLookup = mainMenu;
50 48
	}
51 49

  
52
	@PostConstruct
53
    protected void init() {
54
        eventBus.subscribe(this);
55
	}
56

  
57
	@EventBusListenerMethod
50
	@EventListener
58 51
	protected void doMenuItemLookup(UIInitializedEvent event) {
59 52

  
60 53
		if (mainMenuLookup == null) {
src/main/java/com/vaadin/devday/ui/mainmenu/ValoMainMenuBean.java
6 6
import java.util.stream.StreamSupport;
7 7

  
8 8
import org.springframework.beans.factory.annotation.Autowired;
9
import org.vaadin.spring.events.EventBus;
10
import org.vaadin.spring.events.annotation.EventBusListenerMethod;
9
import org.springframework.context.ApplicationEventPublisher;
10
import org.springframework.context.event.EventListener;
11 11

  
12 12
import com.vaadin.devday.ui.MainMenu;
13 13
import com.vaadin.devday.ui.navigation.AfterViewChangeEvent;
......
39 39
	private Button menuToggle;
40 40

  
41 41
	@Autowired
42
    EventBus.UIEventBus eventBus;
42
    ApplicationEventPublisher eventBus;
43 43

  
44 44
	public ValoMainMenuBean() {
45 45
		setPrimaryStyleName(ValoTheme.MENU_ROOT);
......
80 80
	}
81 81

  
82 82
	private void onMenuItemClicked(String navigationResource) {
83
	    eventBus.publish(this, new NavigationEvent(navigationResource));
83
	    eventBus.publishEvent(new NavigationEvent(navigationResource));
84 84
	}
85 85

  
86
	@EventBusListenerMethod()
86
	@EventListener
87 87
	protected void onNavigationEvent(NavigationEvent e) {
88 88
		List<MainMenuItemBean> menuItems = StreamSupport.stream(menuArea.spliterator(), false)
89 89
				.filter(component -> MainMenuItemBean.class.isAssignableFrom(component.getClass()))
......
97 97
		}
98 98
	}
99 99

  
100
	@EventBusListenerMethod()
100
	@EventListener
101 101
	protected void afterViewChange(AfterViewChangeEvent event) {
102 102
		removeStyleName(MENU_VISIBLE);
103 103
	}
src/main/java/com/vaadin/devday/ui/navigation/NavigationManagerBean.java
4 4
import java.util.Map;
5 5

  
6 6
import org.springframework.beans.factory.annotation.Autowired;
7
import org.vaadin.spring.events.EventBus;
8
import org.vaadin.spring.events.annotation.EventBusListenerMethod;
7
import org.springframework.context.ApplicationEventPublisher;
8
import org.springframework.context.event.EventListener;
9 9

  
10 10
import com.vaadin.devday.ui.NavigationManager;
11 11
import com.vaadin.devday.ui.UIInitializedEvent;
......
32 32
	@Autowired
33 33
	private SpringViewProvider viewProvider;
34 34

  
35
	// @Autowired
35
	@Autowired
36 36
	private ViewChangeListener viewChangeListener;
37 37

  
38 38
	private Map<PopupView, Window> popupMap;
......
41 41
		popupMap = new HashMap<>();
42 42
	}
43 43

  
44
    @Autowired
45
    private Map<String, PopupView> popupViews;
44
	//@Autowired
45
    private Map<String, PopupView> popupViews = null;
46 46

  
47 47
	@Autowired
48 48
	private UriFragmentManager uriFragmentManager;
49 49

  
50 50
	@Autowired
51
	EventBus.UIEventBus eventBus;
51
	ApplicationEventPublisher eventBus;
52 52

  
53
	@EventBusListenerMethod()
53
	@EventListener
54 54
	protected void onUIInitialized(UIInitializedEvent e) {
55 55
		init(UI.getCurrent(), uriFragmentManager, viewDisplay);
56 56
		addProvider(viewProvider);
......
68 68
	@Override
69 69
	public void navigateTo(String navigationState) {
70 70
		super.navigateTo(navigationState);
71
		eventBus.publish(this, new NavigationEvent(navigationState));
71
		eventBus.publishEvent(new NavigationEvent(navigationState));
72 72
	}
73 73

  
74
	@EventBusListenerMethod()
74
	@EventListener
75 75
	protected void onNavigationEvent(NavigationEvent e) {
76 76
		navigateTo(e.getViewName(), false);
77 77
	}
......
95 95
		return (T) popupContent;
96 96
	}
97 97

  
98
    @EventBusListenerMethod()
98
    @EventListener
99 99
	protected void onDoneWithTheEditor(DoneWithPopupEvent e) {
100 100
		Window window = popupMap.get(e.getPopup());
101 101
		if (window != null) {
src/main/java/com/vaadin/devday/ui/navigation/NavigationUriFragmentManager.java
1 1
package com.vaadin.devday.ui.navigation;
2 2

  
3 3
import org.springframework.beans.factory.annotation.Autowired;
4
import org.vaadin.spring.events.EventBus;
4
import org.springframework.context.ApplicationEventPublisher;
5 5

  
6 6
import com.vaadin.navigator.Navigator.UriFragmentManager;
7 7
import com.vaadin.server.Page;
......
16 16
    private static final long serialVersionUID = -2033745435437337863L;
17 17

  
18 18
    @Autowired
19
    EventBus.UIEventBus eventBus;
19
    ApplicationEventPublisher eventBus;
20 20

  
21 21
	public NavigationUriFragmentManager() {
22 22
		super(Page.getCurrent());
......
24 24

  
25 25
	@Override
26 26
	public void uriFragmentChanged(UriFragmentChangedEvent event) {
27
	    eventBus.publish(this, new NavigationEvent(getState()));
27
	    eventBus.publishEvent(new NavigationEvent(getState()));
28 28
	}
29 29
}
src/main/java/com/vaadin/devday/ui/navigation/ViewChangeListenerBean.java
3 3
import java.util.Collection;
4 4

  
5 5
import org.springframework.beans.factory.annotation.Autowired;
6
import org.vaadin.spring.events.EventBus;
6
import org.springframework.context.ApplicationEventPublisher;
7
import org.springframework.context.annotation.Lazy;
7 8

  
8 9
import com.vaadin.devday.ui.NavigationManager;
9 10
import com.vaadin.navigator.View;
......
16 17
class ViewChangeListenerBean implements ViewChangeListener {
17 18
	private static final long serialVersionUID = 1913421359807383L;
18 19

  
19
	@Autowired
20
	private Collection<ViewChangeAllowedVerifier> verifiers;
20
	@Autowired(required=false)
21
	private Collection<ViewChangeAllowedVerifier> verifiers = null;
21 22

  
22 23
	@Autowired
24
	@Lazy
23 25
	private NavigationManager navigationManager;
24 26

  
25 27
	@Autowired
26
    EventBus.UIEventBus eventBus;
28
    ApplicationEventPublisher eventBus;
27 29

  
28 30
	@Override
29 31
	public boolean beforeViewChange(ViewChangeEvent event) {
30 32
		View currentView = navigationManager.getCurrentView();
31
		if (currentView != null) {
33
		if (currentView != null && verifiers != null) {
32 34
			for (ViewChangeAllowedVerifier verifier : verifiers) {
33 35
				if (currentView.equals(verifier)) {
34 36
					if (!verifier.isViewChangeAllowed()) {
......
37 39
				}
38 40
			}
39 41
		}
40

  
41 42
		return true;
42 43
	}
43 44

  
44 45
	@Override
45 46
	public void afterViewChange(ViewChangeEvent event) {
46
	    eventBus.publish(this, new AfterViewChangeEvent());
47
	    eventBus.publishEvent(new AfterViewChangeEvent());
47 48
	}
48 49

  
49 50
}
src/main/java/eu/etaxonomy/cdm/addon/config/CdmVaadinConfiguration.java
13 13
import org.apache.log4j.Logger;
14 14
import org.springframework.context.annotation.ComponentScan;
15 15
import org.springframework.context.annotation.Configuration;
16
import org.vaadin.spring.events.annotation.EnableEventBus;
17 16

  
18 17
import com.vaadin.spring.annotation.EnableVaadin;
19 18
import com.vaadin.spring.server.SpringVaadinServlet;
......
30 29
        "com.vaadin.devday.ui"
31 30
        })
32 31
@EnableVaadin   // this imports VaadinConfiguration
33
@EnableEventBus
34
//@Import(EventBusConfiguration.class)
35 32
public class CdmVaadinConfiguration {
36 33

  
37 34
    public static final Logger logger = Logger.getLogger(CdmVaadinConfiguration.class);
src/main/java/eu/etaxonomy/cdm/vaadin/ui/RegistrationUI.java
9 9
package eu.etaxonomy.cdm.vaadin.ui;
10 10

  
11 11
import org.springframework.beans.factory.annotation.Autowired;
12
import org.springframework.context.ApplicationEventPublisher;
12 13

  
13 14
import com.vaadin.annotations.Theme;
14 15
import com.vaadin.annotations.Title;
15 16
import com.vaadin.annotations.Viewport;
16 17
import com.vaadin.annotations.Widgetset;
18
import com.vaadin.devday.ui.UIInitializedEvent;
17 19
import com.vaadin.navigator.ViewDisplay;
18 20
import com.vaadin.server.Responsive;
19 21
import com.vaadin.server.VaadinRequest;
......
41 43
    private ViewDisplay viewDisplay;
42 44

  
43 45
    @Autowired
44
    // private javax.enterprise.event.Event<UIInitializedEvent> event;
46
    ApplicationEventPublisher eventBus;
45 47

  
46 48
    @Override
47 49
    protected void init(VaadinRequest request) {
......
50 52

  
51 53
        setContent((Component) viewDisplay);
52 54

  
53
        // event.fire(new UIInitializedEvent());
55
        eventBus.publishEvent(new UIInitializedEvent());
54 56
    }
55 57
}

Also available in: Unified diff