]>
git.argeo.org Git - gpl/argeo-suite.git/blob - core/org.argeo.suite.ui/src/org/argeo/suite/ui/SuiteUi.java
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 belowHeader
;
30 private Composite leadPane
;
31 private Composite dynamicArea
;
33 private Session sysSession
;
34 // private Session homeSession;
37 private Map
<String
, SuiteLayer
> layers
= new HashMap
<>();
38 private Map
<String
, Composite
> workAreas
= new HashMap
<>();
39 private String currentLayerId
= null;
41 private CmsView cmsView
;
43 public SuiteUi(Composite parent
, int style
) {
45 cmsView
= CmsView
.getCmsView(parent
);
46 this.setLayout(CmsUiUtils
.noSpaceGridLayout());
48 header
= new Composite(this, SWT
.NONE
);
49 header
.setLayout(CmsUiUtils
.noSpaceGridLayout());
50 CmsUiUtils
.style(header
, SuiteStyle
.header
);
51 header
.setLayoutData(CmsUiUtils
.fillWidth());
53 belowHeader
= new Composite(this, SWT
.NONE
);
54 belowHeader
.setLayoutData(CmsUiUtils
.fillAll());
57 public void refreshBelowHeader(boolean initApp
) {
58 CmsUiUtils
.clear(belowHeader
);
59 int style
= getStyle();
61 belowHeader
.setLayout(CmsUiUtils
.noSpaceGridLayout(2));
63 if (SWT
.RIGHT_TO_LEFT
== (style
& SWT
.RIGHT_TO_LEFT
)) {// arabic, hebrew, etc.
64 dynamicArea
= new Composite(belowHeader
, SWT
.NONE
);
65 leadPane
= new Composite(belowHeader
, SWT
.NONE
);
67 leadPane
= new Composite(belowHeader
, SWT
.NONE
);
68 dynamicArea
= new Composite(belowHeader
, SWT
.NONE
);
70 leadPane
.setLayoutData(CmsUiUtils
.fillHeight());
71 leadPane
.setLayout(CmsUiUtils
.noSpaceGridLayout());
72 CmsUiUtils
.style(leadPane
, SuiteStyle
.leadPane
);
74 dynamicArea
.setLayoutData(CmsUiUtils
.fillAll());
75 dynamicArea
.setLayout(new FormLayout());
78 belowHeader
.setLayout(CmsUiUtils
.noSpaceGridLayout());
86 Composite
getCurrentWorkArea() {
87 if (currentLayerId
== null)
88 throw new IllegalStateException("No current layer");
89 return workAreas
.get(currentLayerId
);
92 String
getCurrentLayerId() {
93 return currentLayerId
;
96 private Composite
getLayer(String id
, Node context
) {
97 if (!layers
.containsKey(id
))
99 if (!workAreas
.containsKey(id
))
100 initLayer(id
, layers
.get(id
), context
);
101 return workAreas
.get(id
);
104 Composite
switchToLayer(String layerId
, Node context
) {
105 Composite current
= null;
106 if (currentLayerId
!= null) {
107 current
= getCurrentWorkArea();
108 if (currentLayerId
.equals(layerId
))
111 if (context
== null) {
112 if (!cmsView
.isAnonymous())
115 Composite toShow
= getLayer(layerId
, context
);
116 if (toShow
!= null) {
117 currentLayerId
= layerId
;
119 // getDisplay().syncExec(() -> {
120 if (!toShow
.isDisposed()) {
121 toShow
.moveAbove(null);
123 log
.warn("Cannot show work area because it is disposed.");
124 toShow
= initLayer(layerId
, layers
.get(layerId
), context
);
125 toShow
.moveAbove(null);
127 dynamicArea
.layout(true, true);
136 Composite
switchToLayer(SuiteLayer layer
, Node context
) {
137 // TODO make it more robust
138 for (String layerId
: layers
.keySet()) {
139 SuiteLayer l
= layers
.get(layerId
);
141 return switchToLayer(layerId
, context
);
144 throw new IllegalArgumentException("Layer is not registered.");
147 void addLayer(String id
, SuiteLayer layer
) {
148 layers
.put(id
, layer
);
151 void removeLayer(String id
) {
153 if (workAreas
.containsKey(id
)) {
154 Composite workArea
= workAreas
.remove(id
);
155 if (!workArea
.isDisposed())
160 protected Composite
initLayer(String id
, SuiteLayer layer
, Node context
) {
161 Composite workArea
= cmsView
.doAs(() -> (Composite
) layer
.createUiPart(dynamicArea
, context
));
162 CmsUiUtils
.style(workArea
, SuiteStyle
.workArea
);
163 workArea
.setLayoutData(CmsUiUtils
.coverAll());
164 workAreas
.put(id
, workArea
);
168 synchronized void logout() {
170 Jcr
.logout(sysSession
);
171 // Jcr.logout(homeSession);
172 currentLayerId
= null;
180 Composite
getHeader() {
184 Composite
getLeadPane() {
188 Composite
getBelowHeader() {
192 // Session getSysSession() {
193 // return sysSession;
196 synchronized void initSessions(Repository repository
, String userDirPath
) throws RepositoryException
{
197 this.sysSession
= repository
.login();
198 // this.homeSession = repository.login(NodeConstants.HOME_WORKSPACE);
199 userDir
= sysSession
.getNode(userDirPath
);
200 addDisposeListener((e
) -> {
201 Jcr
.logout(sysSession
);
202 // Jcr.logout(homeSession);
210 Session
getSysSession() {
214 Session
getSession(String workspaceName
) {
215 if (workspaceName
== null)
217 if (NodeConstants
.SYS_WORKSPACE
.equals(workspaceName
))
219 // else if (NodeConstants.HOME_WORKSPACE.equals(workspaceName))
220 // return homeSession;
222 throw new IllegalArgumentException("Unknown workspace " + workspaceName
);
225 public CmsView
getCmsView() {
229 public Localized
getTitle() {
233 public void setTitle(Localized title
) {