1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package com.tapas.evidence.fe.menu;
20
21 import javax.inject.Inject;
22
23 import org.springframework.context.annotation.Scope;
24 import org.springframework.stereotype.Component;
25 import org.vaadin.mvp.eventbus.EventBus;
26 import org.vaadin.mvp.presenter.BasePresenter;
27 import org.vaadin.mvp.presenter.FactoryPresenter;
28 import org.vaadin.mvp.presenter.annotation.Presenter;
29
30 import com.tapas.evidence.fe.child.ChildPresenter;
31 import com.tapas.evidence.fe.kindergarten.KindergartenPresenter;
32 import com.tapas.evidence.fe.main.MainEventBus;
33 import com.tapas.evidence.fe.responsible.ResponsiblePersonPresenter;
34 import com.tapas.evidence.fe.teacher.TeacherPresenter;
35 import com.tapas.evidence.service.KindergartenService;
36 import com.vaadin.ui.Field.ValueChangeEvent;
37 import com.vaadin.ui.Tree;
38
39
40
41
42
43
44 @Component("menuPresenter")
45 @Scope("prototype")
46 @Presenter(view = MenuView.class)
47 public class MenuPresenter extends FactoryPresenter<IMenuView, MainEventBus> {
48
49 @Inject
50 private KindergartenService kindergartenService;
51
52 @Override
53 public void bind() {
54 final Tree tree = this.view.getTree();
55 addEntry(tree, null, Boolean.FALSE, this.getMessage("menu.kindergarten", this.getLocale()), KindergartenPresenter.class);
56 addEntry(tree, null, Boolean.FALSE, this.getMessage("menu.teacher", this.getLocale()), TeacherPresenter.class);
57 addEntry(tree, null, Boolean.FALSE, this.getMessage("menu.responsible", this.getLocale()), ResponsiblePersonPresenter.class);
58 addEntry(tree, null, Boolean.FALSE, this.getMessage("menu.child", this.getLocale()), ChildPresenter.class);
59 }
60
61 private MenuEntry addEntry(final Tree tree, final MenuEntry parent, final Boolean hasChildren, final String caption,
62 final Class<? extends BasePresenter<?, ? extends EventBus>> presenterType) {
63 final MenuEntry entry = new MenuEntry(caption, presenterType);
64 tree.addItem(entry);
65 tree.setParent(entry, parent);
66 tree.setChildrenAllowed(entry, hasChildren);
67 return entry;
68 }
69
70
71
72
73
74 public void onSelectMenu(final ValueChangeEvent event) {
75
76 final MenuEntry menuEntry = (MenuEntry) this.view.getTree().getValue();
77 if (menuEntry != null) {
78 if (menuEntry.getPresenterType().equals(ChildPresenter.class)) {
79 this.eventBus.openModule(ResponsiblePersonPresenter.class);
80 }
81 this.eventBus.openModule(menuEntry.getPresenterType());
82 }
83 }
84 }