1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.module.googlesitemap.app.subapp.sitemapdetail.base;
35
36 import info.magnolia.event.EventBus;
37 import info.magnolia.i18nsystem.SimpleTranslator;
38 import info.magnolia.module.googlesitemap.app.subapp.sitemapdetail.event.EntrySelectedEvent;
39 import info.magnolia.module.googlesitemap.app.subapp.sitemapdetail.util.SiteMapEntryContainer;
40 import info.magnolia.module.googlesitemap.bean.SiteMapEntry;
41 import info.magnolia.module.googlesitemap.service.SiteMapService;
42 import info.magnolia.ui.api.app.SubAppEventBus;
43
44 import java.util.List;
45
46 import javax.inject.Named;
47 import javax.jcr.Node;
48
49
50
51
52
53 public abstract class SiteMapDetailPresenter<L extends SiteMapContentView.Listener> implements SiteMapContentView.Listener {
54
55 private final SiteMapContentView view;
56
57 private final EventBus eventBus;
58
59 private SimpleTranslator translator;
60
61 protected final SiteMapService service;
62
63 protected SiteMapEntryContainer siteContainer;
64
65 public SiteMapDetailPresenter(
66 SiteMapContentView<L> view,
67 SiteMapService service,
68 @Named(SubAppEventBus.NAME)EventBus eventBus,
69 SimpleTranslator translator) {
70 this.view = view;
71 this.service = service;
72 this.eventBus = eventBus;
73 this.translator = translator;
74 }
75
76 public SiteMapContentView start() {
77 this.view.setListener(getListener());
78 return view;
79 }
80
81 public SimpleTranslator getTranslator() {
82 return translator;
83 }
84
85 public void edit(Node siteMapNode) {
86 constructDataSource(fetchSiteMapEntries(siteMapNode));
87 }
88
89 public abstract String getLabel();
90
91 protected abstract List<SiteMapEntry> fetchSiteMapEntries(Node node);
92
93 protected abstract SiteMapContentView.Listener getListener();
94
95 protected SiteMapContentView getView() {
96 return view;
97 }
98
99 private void constructDataSource(List<SiteMapEntry> siteMapBeanForSite) {
100 this.siteContainer = new SiteMapEntryContainer(siteMapBeanForSite);
101 view.setDatasource(siteContainer);
102 }
103
104 @Override
105 public void onEntrySelected(SiteMapEntry value) {
106 eventBus.fireEvent(new EntrySelectedEvent(value));
107 }
108
109 public SiteMapEntry getCurrentSelection() {
110 return view.getValue();
111 }
112 }