]>
git.argeo.org Git - gpl/argeo-suite.git/blob - 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
.ui
.CmsView
;
15 import org
.argeo
.cms
.ui
.util
.CmsUiUtils
;
16 import org
.argeo
.jcr
.Jcr
;
17 import org
.eclipse
.swt
.SWT
;
18 import org
.eclipse
.swt
.layout
.FormLayout
;
19 import org
.eclipse
.swt
.widgets
.Composite
;
21 /** The view for the default ergonomics of Argeo Suite. */
22 class SuiteUi
extends Composite
{
23 private static final long serialVersionUID
= 6207018859086689108L;
24 private final static Log log
= LogFactory
.getLog(SuiteUi
.class);
25 private Composite header
;
26 private Composite belowHeader
;
27 private Composite leadPane
;
28 private Composite dynamicArea
;
30 private Session sysSession
;
31 // private Session homeSession;
34 private Map
<String
, SuiteLayer
> layers
= new HashMap
<>();
35 private Map
<String
, Composite
> workAreas
= new HashMap
<>();
36 private String currentLayerId
= null;
38 private CmsView cmsView
;
40 public SuiteUi(Composite parent
, int style
) {
42 cmsView
= CmsView
.getCmsView(parent
);
43 this.setLayout(CmsUiUtils
.noSpaceGridLayout());
45 header
= new Composite(this, SWT
.NONE
);
46 CmsUiUtils
.style(header
, SuiteStyle
.header
);
47 header
.setLayoutData(CmsUiUtils
.fillWidth());
49 belowHeader
= new Composite(this, SWT
.NONE
);
50 belowHeader
.setLayoutData(CmsUiUtils
.fillAll());
53 public void refreshBelowHeader(boolean initApp
) {
54 CmsUiUtils
.clear(belowHeader
);
55 int style
= getStyle();
57 belowHeader
.setLayout(CmsUiUtils
.noSpaceGridLayout(2));
59 if (SWT
.RIGHT_TO_LEFT
== (style
& SWT
.RIGHT_TO_LEFT
)) {// arabic, hebrew, etc.
60 dynamicArea
= new Composite(belowHeader
, SWT
.NONE
);
61 leadPane
= new Composite(belowHeader
, SWT
.NONE
);
63 leadPane
= new Composite(belowHeader
, SWT
.NONE
);
64 dynamicArea
= new Composite(belowHeader
, SWT
.NONE
);
66 leadPane
.setLayoutData(CmsUiUtils
.fillHeight());
67 CmsUiUtils
.style(leadPane
, SuiteStyle
.leadPane
);
68 dynamicArea
.setLayoutData(CmsUiUtils
.fillAll());
70 dynamicArea
.setLayout(new FormLayout());
73 belowHeader
.setLayout(CmsUiUtils
.noSpaceGridLayout());
81 Composite
getCurrentWorkArea() {
82 if (currentLayerId
== null)
83 throw new IllegalStateException("No current layer");
84 return workAreas
.get(currentLayerId
);
87 String
getCurrentLayerId() {
88 return currentLayerId
;
91 private Composite
getLayer(String id
, Node context
) {
92 if (!layers
.containsKey(id
))
94 if (!workAreas
.containsKey(id
))
95 initLayer(id
, layers
.get(id
), context
);
96 return workAreas
.get(id
);
99 Composite
switchToLayer(String layerId
, Node context
) {
100 Composite current
= null;
101 if (currentLayerId
!= null) {
102 current
= getCurrentWorkArea();
103 if (currentLayerId
.equals(layerId
))
106 if (context
== null) {
107 if (!cmsView
.isAnonymous())
110 Composite toShow
= getLayer(layerId
, context
);
111 if (toShow
!= null) {
112 currentLayerId
= layerId
;
114 // getDisplay().syncExec(() -> {
115 if (!toShow
.isDisposed()) {
116 toShow
.moveAbove(null);
118 log
.warn("Cannot show work area because it is disposed.");
119 toShow
= initLayer(layerId
, layers
.get(layerId
), context
);
120 toShow
.moveAbove(null);
122 dynamicArea
.layout(true, true);
131 Composite
switchToLayer(SuiteLayer layer
, Node context
) {
132 // TODO make it more robust
133 for (String layerId
: layers
.keySet()) {
134 SuiteLayer l
= layers
.get(layerId
);
136 return switchToLayer(layerId
, context
);
139 throw new IllegalArgumentException("Layer is not registered.");
142 void addLayer(String id
, SuiteLayer layer
) {
143 layers
.put(id
, layer
);
146 void removeLayer(String id
) {
148 if (workAreas
.containsKey(id
)) {
149 Composite workArea
= workAreas
.remove(id
);
150 if (!workArea
.isDisposed())
155 protected Composite
initLayer(String id
, SuiteLayer layer
, Node context
) {
156 Composite workArea
= cmsView
.doAs(() -> (Composite
) layer
.createUiPart(dynamicArea
, context
));
157 workArea
.setLayoutData(CmsUiUtils
.coverAll());
158 workAreas
.put(id
, workArea
);
162 synchronized void logout() {
164 Jcr
.logout(sysSession
);
165 // Jcr.logout(homeSession);
166 currentLayerId
= null;
174 Composite
getHeader() {
178 Composite
getLeadPane() {
182 Composite
getBelowHeader() {
186 // Session getSysSession() {
187 // return sysSession;
190 synchronized void initSessions(Repository repository
, String userDirPath
) throws RepositoryException
{
191 this.sysSession
= repository
.login();
192 // this.homeSession = repository.login(NodeConstants.HOME_WORKSPACE);
193 userDir
= sysSession
.getNode(userDirPath
);
194 addDisposeListener((e
) -> {
195 Jcr
.logout(sysSession
);
196 // Jcr.logout(homeSession);
204 Session
getSysSession() {
208 Session
getSession(String workspaceName
) {
209 if (workspaceName
== null)
211 if (NodeConstants
.SYS_WORKSPACE
.equals(workspaceName
))
213 // else if (NodeConstants.HOME_WORKSPACE.equals(workspaceName))
214 // return homeSession;
216 throw new IllegalArgumentException("Unknown workspace " + workspaceName
);
219 public CmsView
getCmsView() {