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.pages.app.editor.pagebar.platformselector;
35
36 import info.magnolia.event.EventBus;
37 import info.magnolia.pages.app.editor.PageEditorPresenter;
38 import info.magnolia.pages.app.editor.extension.AbstractExtension;
39 import info.magnolia.ui.api.app.SubAppEventBus;
40 import info.magnolia.ui.api.view.View;
41 import info.magnolia.ui.contentapp.detail.DetailLocation;
42 import info.magnolia.ui.contentapp.detail.DetailView;
43 import info.magnolia.ui.vaadin.editor.gwt.shared.PlatformType;
44
45 import javax.inject.Inject;
46 import javax.inject.Named;
47
48
49
50
51 public class PlatformSelector extends AbstractExtension implements PlatformSelectorView.Listener {
52
53 private final EventBus eventBus;
54 private PlatformSelectorView view;
55 private PageEditorPresenter pageEditorPresenter;
56
57
58 @Inject
59 public PlatformSelector(PlatformSelectorView view, PageEditorPresenter pageEditorPresenter, @Named(SubAppEventBus.NAME) EventBus eventBus) {
60 this.view = view;
61 this.pageEditorPresenter = pageEditorPresenter;
62 this.eventBus = eventBus;
63 }
64
65 @Override
66 public View start(DetailLocation location) {
67 view.setListener(this);
68 updatePlatformSelector(location);
69
70 return view;
71 }
72
73 private void updatePlatformSelector(DetailLocation location) {
74 boolean isPreview = DetailView.ViewType.VIEW.equals(location.getViewType());
75 if (!isPreview) {
76 resetCurrentPlatform();
77 }
78 setVisible(isPreview);
79 }
80
81 @Override
82 public void platformSelected(PlatformType platformType) {
83 PlatformType currentPlatFormType = pageEditorPresenter.getStatus().getPlatformType();
84 if (platformType != null && !platformType.equals(currentPlatFormType)) {
85 pageEditorPresenter.getStatus().setPlatformType(platformType);
86 pageEditorPresenter.loadPageEditor();
87 eventBus.fireEvent(new PlatformChangedEvent(platformType));
88 }
89 }
90
91 public void setVisible(boolean visible) {
92 view.setVisible(visible);
93 }
94
95 @Override
96 public void onLocationUpdate(DetailLocation location) {
97 updatePlatformSelector(location);
98 }
99
100 private void resetCurrentPlatform() {
101 pageEditorPresenter.getStatus().setPlatformType(PlatformType.DESKTOP);
102 view.setPlatformType(PlatformType.DESKTOP);
103 }
104
105 @Override
106 public void deactivate() {
107 view.setVisible(false);
108 }
109 }