]>
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
.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 header
.setLayout(CmsUiUtils
.noSpaceGridLayout());
47 CmsUiUtils
.style(header
, SuiteStyle
.header
);
48 header
.setLayoutData(CmsUiUtils
.fillWidth());
50 belowHeader
= new Composite(this, SWT
.NONE
);
51 belowHeader
.setLayoutData(CmsUiUtils
.fillAll());
54 public void refreshBelowHeader(boolean initApp
) {
55 CmsUiUtils
.clear(belowHeader
);
56 int style
= getStyle();
58 belowHeader
.setLayout(CmsUiUtils
.noSpaceGridLayout(2));
60 if (SWT
.RIGHT_TO_LEFT
== (style
& SWT
.RIGHT_TO_LEFT
)) {// arabic, hebrew, etc.
61 dynamicArea
= new Composite(belowHeader
, SWT
.NONE
);
62 leadPane
= new Composite(belowHeader
, SWT
.NONE
);
64 leadPane
= new Composite(belowHeader
, SWT
.NONE
);
65 dynamicArea
= new Composite(belowHeader
, SWT
.NONE
);
67 leadPane
.setLayoutData(CmsUiUtils
.fillHeight());
68 leadPane
.setLayout(CmsUiUtils
.noSpaceGridLayout());
69 CmsUiUtils
.style(leadPane
, SuiteStyle
.leadPane
);
71 dynamicArea
.setLayoutData(CmsUiUtils
.fillAll());
72 dynamicArea
.setLayout(new FormLayout());
75 belowHeader
.setLayout(CmsUiUtils
.noSpaceGridLayout());
83 Composite
getCurrentWorkArea() {
84 if (currentLayerId
== null)
85 throw new IllegalStateException("No current layer");
86 return workAreas
.get(currentLayerId
);
89 String
getCurrentLayerId() {
90 return currentLayerId
;
93 private Composite
getLayer(String id
, Node context
) {
94 if (!layers
.containsKey(id
))
96 if (!workAreas
.containsKey(id
))
97 initLayer(id
, layers
.get(id
), context
);
98 return workAreas
.get(id
);
101 Composite
switchToLayer(String layerId
, Node context
) {
102 Composite current
= null;
103 if (currentLayerId
!= null) {
104 current
= getCurrentWorkArea();
105 if (currentLayerId
.equals(layerId
))
108 if (context
== null) {
109 if (!cmsView
.isAnonymous())
112 Composite toShow
= getLayer(layerId
, context
);
113 if (toShow
!= null) {
114 currentLayerId
= layerId
;
116 // getDisplay().syncExec(() -> {
117 if (!toShow
.isDisposed()) {
118 toShow
.moveAbove(null);
120 log
.warn("Cannot show work area because it is disposed.");
121 toShow
= initLayer(layerId
, layers
.get(layerId
), context
);
122 toShow
.moveAbove(null);
124 dynamicArea
.layout(true, true);
133 Composite
switchToLayer(SuiteLayer layer
, Node context
) {
134 // TODO make it more robust
135 for (String layerId
: layers
.keySet()) {
136 SuiteLayer l
= layers
.get(layerId
);
138 return switchToLayer(layerId
, context
);
141 throw new IllegalArgumentException("Layer is not registered.");
144 void addLayer(String id
, SuiteLayer layer
) {
145 layers
.put(id
, layer
);
148 void removeLayer(String id
) {
150 if (workAreas
.containsKey(id
)) {
151 Composite workArea
= workAreas
.remove(id
);
152 if (!workArea
.isDisposed())
157 protected Composite
initLayer(String id
, SuiteLayer layer
, Node context
) {
158 Composite workArea
= cmsView
.doAs(() -> (Composite
) layer
.createUiPart(dynamicArea
, context
));
159 CmsUiUtils
.style(workArea
, SuiteStyle
.workArea
);
160 workArea
.setLayoutData(CmsUiUtils
.coverAll());
161 workAreas
.put(id
, workArea
);
165 synchronized void logout() {
167 Jcr
.logout(sysSession
);
168 // Jcr.logout(homeSession);
169 currentLayerId
= null;
177 Composite
getHeader() {
181 Composite
getLeadPane() {
185 Composite
getBelowHeader() {
189 // Session getSysSession() {
190 // return sysSession;
193 synchronized void initSessions(Repository repository
, String userDirPath
) throws RepositoryException
{
194 this.sysSession
= repository
.login();
195 // this.homeSession = repository.login(NodeConstants.HOME_WORKSPACE);
196 userDir
= sysSession
.getNode(userDirPath
);
197 addDisposeListener((e
) -> {
198 Jcr
.logout(sysSession
);
199 // Jcr.logout(homeSession);
207 Session
getSysSession() {
211 Session
getSession(String workspaceName
) {
212 if (workspaceName
== null)
214 if (NodeConstants
.SYS_WORKSPACE
.equals(workspaceName
))
216 // else if (NodeConstants.HOME_WORKSPACE.equals(workspaceName))
217 // return homeSession;
219 throw new IllegalArgumentException("Unknown workspace " + workspaceName
);
222 public CmsView
getCmsView() {