]>
git.argeo.org Git - gpl/argeo-suite.git/blob - org.argeo.app.ui/src/org/argeo/app/ui/SuiteUi.java
1 package org
.argeo
.app
.ui
;
3 import java
.util
.HashMap
;
6 import org
.argeo
.api
.acr
.Content
;
7 import org
.argeo
.api
.cms
.CmsLog
;
8 import org
.argeo
.api
.cms
.ux
.CmsUi
;
9 import org
.argeo
.api
.cms
.ux
.CmsView
;
10 import org
.argeo
.cms
.Localized
;
11 import org
.argeo
.cms
.swt
.CmsSwtUtils
;
12 import org
.eclipse
.swt
.SWT
;
13 import org
.eclipse
.swt
.layout
.FormLayout
;
14 import org
.eclipse
.swt
.widgets
.Composite
;
16 /** The view for the default ergonomics of Argeo Suite. */
17 class SuiteUi
extends Composite
implements CmsUi
{
18 private static final long serialVersionUID
= 6207018859086689108L;
19 private final static CmsLog log
= CmsLog
.getLog(SuiteUi
.class);
21 private Localized title
;
22 private Composite header
;
23 private Composite footer
;
24 private Composite belowHeader
;
25 private Composite leadPane
;
26 private Composite sidePane
;
27 private Composite dynamicArea
;
29 // private Session sysSession;
30 // private Session homeSession;
31 private Content userDir
;
33 private Map
<String
, SuiteLayer
> layers
= new HashMap
<>();
34 private Map
<String
, Composite
> workAreas
= new HashMap
<>();
35 private String currentLayerId
= null;
37 private CmsView cmsView
;
39 public SuiteUi(Composite parent
, int style
) {
41 cmsView
= CmsSwtUtils
.getCmsView(parent
);
42 this.setLayout(CmsSwtUtils
.noSpaceGridLayout());
44 header
= new Composite(this, SWT
.NONE
);
45 header
.setLayout(CmsSwtUtils
.noSpaceGridLayout());
46 CmsSwtUtils
.style(header
, SuiteStyle
.header
);
47 header
.setLayoutData(CmsSwtUtils
.fillWidth());
49 belowHeader
= new Composite(this, SWT
.NONE
);
50 belowHeader
.setLayoutData(CmsSwtUtils
.fillAll());
52 footer
= new Composite(this, SWT
.NONE
);
53 footer
.setLayout(CmsSwtUtils
.noSpaceGridLayout());
54 CmsSwtUtils
.style(footer
, SuiteStyle
.footer
);
55 footer
.setLayoutData(CmsSwtUtils
.fillWidth());
58 public void refreshBelowHeader(boolean initApp
) {
59 CmsSwtUtils
.clear(belowHeader
);
60 int style
= getStyle();
62 belowHeader
.setLayout(CmsSwtUtils
.noSpaceGridLayout(3));
64 if (SWT
.RIGHT_TO_LEFT
== (style
& SWT
.RIGHT_TO_LEFT
)) {// arabic, hebrew, etc.
65 sidePane
= new Composite(belowHeader
, SWT
.NONE
);
66 sidePane
.setLayout(CmsSwtUtils
.noSpaceGridLayout());
67 sidePane
.setLayoutData(CmsSwtUtils
.fillHeight());
68 dynamicArea
= new Composite(belowHeader
, SWT
.NONE
);
69 leadPane
= new Composite(belowHeader
, SWT
.NONE
);
71 leadPane
= new Composite(belowHeader
, SWT
.NONE
);
72 dynamicArea
= new Composite(belowHeader
, SWT
.NONE
);
73 sidePane
= new Composite(belowHeader
, SWT
.NONE
);
74 sidePane
.setLayout(CmsSwtUtils
.noSpaceGridLayout());
75 sidePane
.setLayoutData(CmsSwtUtils
.fillHeight());
77 leadPane
.setLayoutData(CmsSwtUtils
.fillHeight());
78 leadPane
.setLayout(CmsSwtUtils
.noSpaceGridLayout());
79 CmsSwtUtils
.style(leadPane
, SuiteStyle
.leadPane
);
81 dynamicArea
.setLayoutData(CmsSwtUtils
.fillAll());
82 dynamicArea
.setLayout(new FormLayout());
85 belowHeader
.setLayout(CmsSwtUtils
.noSpaceGridLayout());
93 Composite
getCurrentWorkArea() {
94 if (currentLayerId
== null)
95 throw new IllegalStateException("No current layer");
96 return workAreas
.get(currentLayerId
);
99 String
getCurrentLayerId() {
100 return currentLayerId
;
103 private Composite
getLayer(String id
, Content context
) {
104 if (!layers
.containsKey(id
))
106 if (!workAreas
.containsKey(id
))
107 initLayer(id
, layers
.get(id
), context
);
108 return workAreas
.get(id
);
111 Composite
switchToLayer(String layerId
, Content context
) {
112 Composite current
= null;
113 if (currentLayerId
!= null) {
114 current
= getCurrentWorkArea();
115 if (currentLayerId
.equals(layerId
))
118 if (context
== null) {
119 if (!cmsView
.isAnonymous())
120 context
= getUserDirNode();
122 Composite toShow
= getLayer(layerId
, context
);
123 if (toShow
!= null) {
124 currentLayerId
= layerId
;
126 // getDisplay().syncExec(() -> {
127 if (!toShow
.isDisposed()) {
128 toShow
.moveAbove(null);
130 log
.warn("Cannot show work area because it is disposed.");
131 toShow
= initLayer(layerId
, layers
.get(layerId
), context
);
132 toShow
.moveAbove(null);
134 dynamicArea
.layout(true, true);
143 Composite
switchToLayer(SuiteLayer layer
, Content context
) {
144 // TODO make it more robust
145 for (String layerId
: layers
.keySet()) {
146 SuiteLayer l
= layers
.get(layerId
);
148 return switchToLayer(layerId
, context
);
151 throw new IllegalArgumentException("Layer is not registered.");
154 void addLayer(String id
, SuiteLayer layer
) {
155 layers
.put(id
, layer
);
158 void removeLayer(String id
) {
160 if (workAreas
.containsKey(id
)) {
161 Composite workArea
= workAreas
.remove(id
);
162 if (!workArea
.isDisposed())
167 protected Composite
initLayer(String id
, SuiteLayer layer
, Content context
) {
168 Composite workArea
= cmsView
.doAs(() -> (Composite
) layer
.createUiPart(dynamicArea
, context
));
169 CmsSwtUtils
.style(workArea
, SuiteStyle
.workArea
);
170 workArea
.setLayoutData(CmsSwtUtils
.coverAll());
171 workAreas
.put(id
, workArea
);
175 synchronized void logout() {
177 // Jcr.logout(sysSession);
178 // Jcr.logout(homeSession);
179 currentLayerId
= null;
187 Composite
getHeader() {
191 Composite
getFooter() {
195 Composite
getLeadPane() {
199 Composite
getSidePane() {
203 Composite
getBelowHeader() {
207 // Session getSysSession() {
208 // return sysSession;
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);
222 Content
getUserDirNode() {
228 Content
getUserDir() {
232 void setUserDir(Content userDir
) {
233 this.userDir
= userDir
;
236 // Session getSysSession() {
237 // return sysSession;
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;
248 // throw new IllegalArgumentException("Unknown workspace " + workspaceName);
251 public CmsView
getCmsView() {
255 public Localized
getTitle() {
259 public void setTitle(Localized title
) {