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.ui.framework.app;
35
36 import info.magnolia.ui.api.app.AppContext;
37 import info.magnolia.ui.api.app.SubApp;
38 import info.magnolia.ui.api.app.SubAppContext;
39 import info.magnolia.ui.api.location.Location;
40 import info.magnolia.ui.api.view.View;
41 import info.magnolia.ui.framework.UiFrameworkView;
42 import info.magnolia.ui.framework.ioc.UiContextReference;
43
44 import org.apache.commons.lang3.StringUtils;
45 import org.slf4j.Logger;
46 import org.slf4j.LoggerFactory;
47
48
49
50
51
52
53
54
55 public class BaseSubApp<V extends View> implements SubApp, UiFrameworkView {
56
57 private static final Logger log = LoggerFactory.getLogger(BaseSubApp.class);
58
59 private final SubAppContext subAppContext;
60 private final V view;
61
62 protected BaseSubApp(final SubAppContext subAppContext, final V view) {
63 if (subAppContext == null || view == null) {
64 throw new IllegalArgumentException("Constructor does not allow for null args. Found SubAppContext = " + subAppContext + ", View = " + view);
65 }
66 this.subAppContext = subAppContext;
67 this.view = view;
68 }
69
70 @Override
71 public V start(Location location) {
72 onSubAppStart();
73 return view;
74 }
75
76 @Override
77 public void stop() {
78 onSubAppStop();
79 }
80
81 @Override
82 public void locationChanged(Location location) {
83 }
84
85
86
87
88
89
90
91 @Override
92 public boolean supportsLocation(Location location) {
93 return true;
94 }
95
96 @Override
97 public UiContextReference getCurrentViewReference() {
98 return UiContextReference.ofSubApp(getSubAppContext());
99 }
100
101
102
103
104
105 protected void onSubAppStart() {
106 }
107
108
109
110
111
112 protected void onSubAppStop() {
113 }
114
115 public SubAppContext getSubAppContext() {
116 return subAppContext;
117 }
118
119 @Override
120 public String getSubAppId() {
121 return subAppContext.getSubAppId();
122 }
123
124 @Override
125 public V getView() {
126 return view;
127 }
128
129 public AppContext getAppContext() {
130 return subAppContext.getAppContext();
131 }
132
133
134
135
136
137
138
139 @Override
140 public String getCaption() {
141 String label = subAppContext.getSubAppDescriptor().getLabel();
142 if (StringUtils.isNotBlank(label)) {
143 return label;
144 }
145 label = subAppContext.getAppContext().getLabel();
146 if (StringUtils.isNotBlank(label)) {
147 return label;
148 }
149 log.warn("No label could be found for sub app [{}] in app [{}]", subAppContext.getSubAppDescriptor().getName(), subAppContext.getAppContext().getName());
150 return "";
151 }
152
153 protected Location getCurrentLocation() {
154 return getSubAppContext().getLocation();
155 }
156
157 @Override
158 public boolean isCloseable() {
159 return subAppContext.getSubAppDescriptor().isClosable();
160 }
161
162 @Override
163 public String getIcon(Location location) {
164 return subAppContext.getSubAppDescriptor().getIcon();
165 }
166 }