]>
git.argeo.org Git - gpl/argeo-suite.git/blob - SuiteUi.java
187888e55e0190d4b5a2cd8b2998627622d46ddb
1 package org
.argeo
.suite
.ui
;
3 import java
.util
.HashMap
;
7 import javax
.jcr
.Repository
;
8 import javax
.jcr
.RepositoryException
;
9 import javax
.jcr
.Session
;
11 import org
.apache
.commons
.logging
.Log
;
12 import org
.apache
.commons
.logging
.LogFactory
;
13 import org
.argeo
.api
.NodeConstants
;
14 import org
.argeo
.cms
.Localized
;
15 import org
.argeo
.cms
.ui
.CmsView
;
16 import org
.argeo
.cms
.ui
.util
.CmsUiUtils
;
17 import org
.argeo
.jcr
.Jcr
;
18 import org
.eclipse
.swt
.SWT
;
19 import org
.eclipse
.swt
.layout
.FormLayout
;
20 import org
.eclipse
.swt
.widgets
.Composite
;
22 /** The view for the default ergonomics of Argeo Suite. */
23 class SuiteUi
extends Composite
{
24 private static final long serialVersionUID
= 6207018859086689108L;
25 private final static Log log
= LogFactory
.getLog(SuiteUi
.class);
27 private Localized title
;
28 private Composite header
;
29 private Composite footer
;
30 private Composite belowHeader
;
31 private Composite leadPane
;
32 private Composite dynamicArea
;
34 private Session sysSession
;
35 private Session homeSession
;
38 private Map
<String
, SuiteLayer
> layers
= new HashMap
<>();
39 private Map
<String
, Composite
> workAreas
= new HashMap
<>();
40 private String currentLayerId
= null;
42 private CmsView cmsView
;
44 public SuiteUi(Composite parent
, int style
) {
46 cmsView
= CmsView
.getCmsView(parent
);
47 this.setLayout(CmsUiUtils
.noSpaceGridLayout());
49 header
= new Composite(this, SWT
.NONE
);
50 header
.setLayout(CmsUiUtils
.noSpaceGridLayout());
51 CmsUiUtils
.style(header
, SuiteStyle
.header
);
52 header
.setLayoutData(CmsUiUtils
.fillWidth());
54 belowHeader
= new Composite(this, SWT
.NONE
);
55 belowHeader
.setLayoutData(CmsUiUtils
.fillAll());
57 footer
= new Composite(this, SWT
.NONE
);
58 footer
.setLayout(CmsUiUtils
.noSpaceGridLayout());
59 CmsUiUtils
.style(footer
, SuiteStyle
.footer
);
60 footer
.setLayoutData(CmsUiUtils
.fillWidth());
63 public void refreshBelowHeader(boolean initApp
) {
64 CmsUiUtils
.clear(belowHeader
);
65 int style
= getStyle();
67 belowHeader
.setLayout(CmsUiUtils
.noSpaceGridLayout(2));
69 if (SWT
.RIGHT_TO_LEFT
== (style
& SWT
.RIGHT_TO_LEFT
)) {// arabic, hebrew, etc.
70 dynamicArea
= new Composite(belowHeader
, SWT
.NONE
);
71 leadPane
= new Composite(belowHeader
, SWT
.NONE
);
73 leadPane
= new Composite(belowHeader
, SWT
.NONE
);
74 dynamicArea
= new Composite(belowHeader
, SWT
.NONE
);
76 leadPane
.setLayoutData(CmsUiUtils
.fillHeight());
77 leadPane
.setLayout(CmsUiUtils
.noSpaceGridLayout());
78 CmsUiUtils
.style(leadPane
, SuiteStyle
.leadPane
);
80 dynamicArea
.setLayoutData(CmsUiUtils
.fillAll());
81 dynamicArea
.setLayout(new FormLayout());
84 belowHeader
.setLayout(CmsUiUtils
.noSpaceGridLayout());
92 Composite
getCurrentWorkArea() {
93 if (currentLayerId
== null)
94 throw new IllegalStateException("No current layer");
95 return workAreas
.get(currentLayerId
);
98 String
getCurrentLayerId() {
99 return currentLayerId
;
102 private Composite
getLayer(String id
, Node context
) {
103 if (!layers
.containsKey(id
))
105 if (!workAreas
.containsKey(id
))
106 initLayer(id
, layers
.get(id
), context
);
107 return workAreas
.get(id
);
110 Composite
switchToLayer(String layerId
, Node context
) {
111 Composite current
= null;
112 if (currentLayerId
!= null) {
113 current
= getCurrentWorkArea();
114 if (currentLayerId
.equals(layerId
))
117 if (context
== null) {
118 if (!cmsView
.isAnonymous())
121 Composite toShow
= getLayer(layerId
, context
);
122 if (toShow
!= null) {
123 currentLayerId
= layerId
;
125 // getDisplay().syncExec(() -> {
126 if (!toShow
.isDisposed()) {
127 toShow
.moveAbove(null);
129 log
.warn("Cannot show work area because it is disposed.");
130 toShow
= initLayer(layerId
, layers
.get(layerId
), context
);
131 toShow
.moveAbove(null);
133 dynamicArea
.layout(true, true);
142 Composite
switchToLayer(SuiteLayer layer
, Node context
) {
143 // TODO make it more robust
144 for (String layerId
: layers
.keySet()) {
145 SuiteLayer l
= layers
.get(layerId
);
147 return switchToLayer(layerId
, context
);
150 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
, Node context
) {
168 Composite workArea
= cmsView
.doAs(() -> (Composite
) layer
.createUiPart(dynamicArea
, context
));
169 CmsUiUtils
.style(workArea
, SuiteStyle
.workArea
);
170 workArea
.setLayoutData(CmsUiUtils
.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
getBelowHeader() {
203 // Session getSysSession() {
204 // return sysSession;
207 synchronized void initSessions(Repository repository
, String userDirPath
) throws RepositoryException
{
208 this.sysSession
= repository
.login();
209 this.homeSession
= repository
.login(NodeConstants
.HOME_WORKSPACE
);
210 userDir
= sysSession
.getNode(userDirPath
);
211 addDisposeListener((e
) -> {
212 Jcr
.logout(sysSession
);
213 Jcr
.logout(homeSession
);
221 Session
getSysSession() {
225 Session
getSession(String workspaceName
) {
226 if (workspaceName
== null)
228 if (NodeConstants
.SYS_WORKSPACE
.equals(workspaceName
))
230 else if (NodeConstants
.HOME_WORKSPACE
.equals(workspaceName
))
233 throw new IllegalArgumentException("Unknown workspace " + workspaceName
);
236 public CmsView
getCmsView() {
240 public Localized
getTitle() {
244 public void setTitle(Localized title
) {