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.UIComponent;
37 import info.magnolia.ui.api.app.AppContext;
38 import info.magnolia.ui.api.app.SubApp;
39 import info.magnolia.ui.api.app.SubAppContext;
40 import info.magnolia.ui.api.location.Location;
41 import info.magnolia.ui.api.view.View;
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, UIComponent {
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 StringUtils.equals(location.getAppName(), getAppContext().getAppDescriptor().getName()) &&
94 StringUtils.equals(location.getSubAppId(), getSubAppId());
95 }
96
97 @Override
98 public UiContextReference getCurrentViewReference() {
99 return UiContextReference.ofSubApp(getSubAppContext());
100 }
101
102
103
104
105
106 protected void onSubAppStart() {
107 }
108
109
110
111
112
113 protected void onSubAppStop() {
114 }
115
116 public SubAppContext getSubAppContext() {
117 return subAppContext;
118 }
119
120 @Override
121 public String getSubAppId() {
122 return subAppContext.getSubAppId();
123 }
124
125 @Override
126 public V getView() {
127 return view;
128 }
129
130 public AppContext getAppContext() {
131 return subAppContext.getAppContext();
132 }
133
134
135
136
137
138
139
140 @Override
141 public String getCaption() {
142 String label = subAppContext.getSubAppDescriptor().getLabel();
143 if (StringUtils.isNotBlank(label)) {
144 return label;
145 }
146 label = subAppContext.getAppContext().getLabel();
147 if (StringUtils.isNotBlank(label)) {
148 return label;
149 }
150 log.warn("No label could be found for sub app [{}] in app [{}]", subAppContext.getSubAppDescriptor().getName(), subAppContext.getAppContext().getName());
151 return "";
152 }
153
154 protected Location getCurrentLocation() {
155 return getSubAppContext().getLocation();
156 }
157
158 @Override
159 public boolean isCloseable() {
160 return subAppContext.getSubAppDescriptor().isClosable();
161 }
162
163 @Override
164 public String getIcon(Location location) {
165 return subAppContext.getSubAppDescriptor().getIcon();
166 }
167
168 @Override
169 public void destroy() {
170 }
171 }