]> git.argeo.org Git - gpl/argeo-suite.git/blob - SuiteUi.java
02ff38e73a2b969759b493466609bc04c24d6e8b
[gpl/argeo-suite.git] / SuiteUi.java
1 package org.argeo.app.ui;
2
3 import java.util.HashMap;
4 import java.util.Map;
5
6 import org.argeo.api.acr.Content;
7 import org.argeo.api.cms.CmsLog;
8 import org.argeo.cms.Localized;
9 import org.argeo.cms.swt.CmsSwtUi;
10 import org.argeo.cms.swt.CmsSwtUtils;
11 import org.eclipse.swt.SWT;
12 import org.eclipse.swt.layout.FormLayout;
13 import org.eclipse.swt.widgets.Composite;
14
15 /** The view for the default ergonomics of Argeo Suite. */
16 class SuiteUi extends CmsSwtUi {
17 private static final long serialVersionUID = 6207018859086689108L;
18 private final static CmsLog log = CmsLog.getLog(SuiteUi.class);
19
20 private Localized title;
21 private Composite header;
22 private Composite footer;
23 private Composite belowHeader;
24 private Composite leadPane;
25 private Composite sidePane;
26 private Composite dynamicArea;
27
28 // private Session sysSession;
29 // private Session homeSession;
30 private Content userDir;
31
32 private Map<String, SuiteLayer> layers = new HashMap<>();
33 private Map<String, Composite> workAreas = new HashMap<>();
34 private String currentLayerId = null;
35
36 private boolean loginScreen = false;
37 // private String postLoginState;
38
39 public SuiteUi(Composite parent, int style) {
40 super(parent, style);
41 this.setLayout(CmsSwtUtils.noSpaceGridLayout());
42
43 header = new Composite(this, SWT.NONE);
44 header.setLayout(CmsSwtUtils.noSpaceGridLayout());
45 CmsSwtUtils.style(header, SuiteStyle.header);
46 header.setLayoutData(CmsSwtUtils.fillWidth());
47
48 belowHeader = new Composite(this, SWT.NONE);
49 belowHeader.setLayoutData(CmsSwtUtils.fillAll());
50
51 footer = new Composite(this, SWT.NONE);
52 footer.setLayout(CmsSwtUtils.noSpaceGridLayout());
53 CmsSwtUtils.style(footer, SuiteStyle.footer);
54 footer.setLayoutData(CmsSwtUtils.fillWidth());
55 }
56
57 public void refreshBelowHeader(boolean initApp) {
58 CmsSwtUtils.clear(belowHeader);
59 int style = getStyle();
60 if (initApp) {
61 belowHeader.setLayout(CmsSwtUtils.noSpaceGridLayout(3));
62
63 if (SWT.RIGHT_TO_LEFT == (style & SWT.RIGHT_TO_LEFT)) {// arabic, hebrew, etc.
64 sidePane = new Composite(belowHeader, SWT.NONE);
65 sidePane.setLayout(CmsSwtUtils.noSpaceGridLayout());
66 sidePane.setLayoutData(CmsSwtUtils.fillHeight());
67 dynamicArea = new Composite(belowHeader, SWT.NONE);
68 leadPane = new Composite(belowHeader, SWT.NONE);
69 } else {
70 leadPane = new Composite(belowHeader, SWT.NONE);
71 dynamicArea = new Composite(belowHeader, SWT.NONE);
72 sidePane = new Composite(belowHeader, SWT.NONE);
73 sidePane.setLayout(CmsSwtUtils.noSpaceGridLayout());
74 sidePane.setLayoutData(CmsSwtUtils.fillHeight());
75 }
76 leadPane.setLayoutData(CmsSwtUtils.fillHeight());
77 leadPane.setLayout(CmsSwtUtils.noSpaceGridLayout());
78 CmsSwtUtils.style(leadPane, SuiteStyle.leadPane);
79
80 dynamicArea.setLayoutData(CmsSwtUtils.fillAll());
81 dynamicArea.setLayout(new FormLayout());
82
83 } else {
84 belowHeader.setLayout(CmsSwtUtils.noSpaceGridLayout());
85 }
86 }
87
88 /*
89 * LAYERS
90 */
91
92 Composite getCurrentWorkArea() {
93 if (currentLayerId == null)
94 throw new IllegalStateException("No current layer");
95 return workAreas.get(currentLayerId);
96 }
97
98 String getCurrentLayerId() {
99 return currentLayerId;
100 }
101
102 private Composite getLayer(String id, Content context) {
103 if (!layers.containsKey(id))
104 return null;
105 if (!workAreas.containsKey(id))
106 initLayer(id, layers.get(id), context);
107 return workAreas.get(id);
108 }
109
110 Composite switchToLayer(String layerId, Content context) {
111 Composite current = null;
112 if (currentLayerId != null) {
113 current = getCurrentWorkArea();
114 if (currentLayerId.equals(layerId))
115 return current;
116 }
117 if (context == null) {
118 if (!getCmsView().isAnonymous())
119 context = getUserDirNode();
120 }
121 Composite toShow = getLayer(layerId, context);
122 if (toShow != null) {
123 currentLayerId = layerId;
124 if (!isDisposed()) {
125 // getDisplay().syncExec(() -> {
126 if (!toShow.isDisposed()) {
127 toShow.moveAbove(null);
128 } else {
129 log.warn("Cannot show work area because it is disposed.");
130 toShow = initLayer(layerId, layers.get(layerId), context);
131 toShow.moveAbove(null);
132 }
133 dynamicArea.layout(true, true);
134 // });
135 }
136 return toShow;
137 } else {
138 return current;
139 }
140 }
141
142 void switchToLayer(SuiteLayer layer, Content context) {
143 // TODO make it more robust
144 for (String layerId : layers.keySet()) {
145 SuiteLayer l = layers.get(layerId);
146 if (layer.getId().equals(l.getId())) {
147 switchToLayer(layerId, context);
148 return;
149 }
150 }
151 throw new IllegalArgumentException("Layer is not registered.");
152 }
153
154 void addLayer(String id, SuiteLayer layer) {
155 layers.put(id, layer);
156 }
157
158 void removeLayer(String id) {
159 layers.remove(id);
160 if (workAreas.containsKey(id)) {
161 Composite workArea = workAreas.remove(id);
162 if (!workArea.isDisposed())
163 workArea.dispose();
164 }
165 }
166
167 protected Composite initLayer(String id, SuiteLayer layer, Content context) {
168 Composite workArea = getCmsView().doAs(() -> (Composite) layer.createUiPart(dynamicArea, context));
169 CmsSwtUtils.style(workArea, SuiteStyle.workArea);
170 workArea.setLayoutData(CmsSwtUtils.coverAll());
171 workAreas.put(id, workArea);
172 return workArea;
173 }
174
175 synchronized void logout() {
176 userDir = null;
177 // Jcr.logout(sysSession);
178 // Jcr.logout(homeSession);
179 currentLayerId = null;
180 workAreas.clear();
181 }
182
183 /*
184 * GETTERS / SETTERS
185 */
186
187 Composite getHeader() {
188 return header;
189 }
190
191 Composite getFooter() {
192 return footer;
193 }
194
195 Composite getLeadPane() {
196 return leadPane;
197 }
198
199 Composite getSidePane() {
200 return sidePane;
201 }
202
203 Composite getBelowHeader() {
204 return belowHeader;
205 }
206
207 // Session getSysSession() {
208 // return sysSession;
209 // }
210 //
211 // synchronized void initSessions(Repository repository, String userDirPath) throws RepositoryException {
212 // this.sysSession = repository.login();
213 // this.homeSession = repository.login(CmsConstants.HOME_WORKSPACE);
214 // userDir = sysSession.getNode(userDirPath);
215 // addDisposeListener((e) -> {
216 // Jcr.logout(sysSession);
217 // Jcr.logout(homeSession);
218 // });
219 // }
220
221 @Deprecated
222 Content getUserDirNode() {
223 if (userDir == null)
224 return null;
225 return userDir;
226 }
227
228 Content getUserDir() {
229 return userDir;
230 }
231
232 void setUserDir(Content userDir) {
233 this.userDir = userDir;
234 }
235
236 // Session getSysSession() {
237 // return sysSession;
238 // }
239
240 // Session getSession(String workspaceName) {
241 // if (workspaceName == null)
242 // return sysSession;
243 // if (CmsConstants.SYS_WORKSPACE.equals(workspaceName))
244 // return sysSession;
245 // else if (CmsConstants.HOME_WORKSPACE.equals(workspaceName))
246 // return homeSession;
247 // else
248 // throw new IllegalArgumentException("Unknown workspace " + workspaceName);
249 // }
250
251 public Localized getTitle() {
252 return title;
253 }
254
255 public void setTitle(Localized title) {
256 this.title = title;
257 }
258
259 public boolean isLoginScreen() {
260 return loginScreen;
261 }
262
263 public void setLoginScreen(boolean loginScreen) {
264 this.loginScreen = loginScreen;
265 }
266
267 // public String getPostLoginState() {
268 // return postLoginState;
269 // }
270 //
271 // public void setPostLoginState(String postLoginState) {
272 // this.postLoginState = postLoginState;
273 // }
274
275 }