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