]>
git.argeo.org Git - gpl/argeo-suite.git/blob - swt/org.argeo.app.swt/src/org/argeo/app/swt/ux/SwtAppUi.java
1 package org
.argeo
.app
.swt
.ux
;
3 import java
.util
.HashMap
;
6 import org
.argeo
.api
.acr
.Content
;
7 import org
.argeo
.api
.cms
.CmsLog
;
8 import org
.argeo
.app
.ux
.AppUi
;
9 import org
.argeo
.app
.ux
.SuiteStyle
;
10 import org
.argeo
.cms
.Localized
;
11 import org
.argeo
.cms
.swt
.CmsSwtUi
;
12 import org
.argeo
.cms
.swt
.CmsSwtUtils
;
13 import org
.eclipse
.swt
.SWT
;
14 import org
.eclipse
.swt
.layout
.FormLayout
;
15 import org
.eclipse
.swt
.widgets
.Composite
;
17 /** The view for the default UX of Argeo Suite. */
18 public class SwtAppUi
extends CmsSwtUi
implements AppUi
{
19 static enum Structural
{
20 header
, footer
, leadPane
, sidePane
, loginScreen
, adminLeadPane
;
23 private static final long serialVersionUID
= 6207018859086689108L;
24 private final static CmsLog log
= CmsLog
.getLog(SwtAppUi
.class);
26 private Localized title
;
27 private Composite header
;
28 private Composite footer
;
29 private Composite belowHeader
;
30 private Composite leadPane
;
31 private Composite sidePane
;
32 private Composite dynamicArea
;
34 private Content userDir
;
36 private Map
<String
, SwtAppLayer
> layers
= new HashMap
<>();
37 private Map
<String
, Composite
> workAreas
= new HashMap
<>();
38 private String currentLayerId
= null;
40 private boolean loginScreen
= false;
42 public SwtAppUi(Composite parent
, int style
) {
44 this.setLayout(CmsSwtUtils
.noSpaceGridLayout());
46 header
= new Composite(this, SWT
.NONE
);
47 header
.setLayout(CmsSwtUtils
.noSpaceGridLayout());
48 CmsSwtUtils
.style(header
, SuiteStyle
.header
);
49 header
.setLayoutData(CmsSwtUtils
.fillWidth());
51 belowHeader
= new Composite(this, SWT
.NONE
);
52 belowHeader
.setLayoutData(CmsSwtUtils
.fillAll());
54 footer
= new Composite(this, SWT
.NONE
);
55 footer
.setLayout(CmsSwtUtils
.noSpaceGridLayout());
56 CmsSwtUtils
.style(footer
, SuiteStyle
.footer
);
57 footer
.setLayoutData(CmsSwtUtils
.fillWidth());
60 public void refreshBelowHeader(boolean initApp
) {
61 CmsSwtUtils
.clear(belowHeader
);
62 int style
= getStyle();
64 belowHeader
.setLayout(CmsSwtUtils
.noSpaceGridLayout(3));
66 if (SWT
.RIGHT_TO_LEFT
== (style
& SWT
.RIGHT_TO_LEFT
)) {// arabic, hebrew, etc.
67 sidePane
= new Composite(belowHeader
, SWT
.NONE
);
68 sidePane
.setLayout(CmsSwtUtils
.noSpaceGridLayout());
69 sidePane
.setLayoutData(CmsSwtUtils
.fillHeight());
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
);
75 sidePane
= new Composite(belowHeader
, SWT
.NONE
);
76 sidePane
.setLayout(CmsSwtUtils
.noSpaceGridLayout());
77 sidePane
.setLayoutData(CmsSwtUtils
.fillHeight());
79 leadPane
.setLayoutData(CmsSwtUtils
.fillHeight());
80 leadPane
.setLayout(CmsSwtUtils
.noSpaceGridLayout());
81 CmsSwtUtils
.style(leadPane
, SuiteStyle
.leadPane
);
83 dynamicArea
.setLayoutData(CmsSwtUtils
.fillAll());
84 dynamicArea
.setLayout(new FormLayout());
87 belowHeader
.setLayout(CmsSwtUtils
.noSpaceGridLayout());
95 public Composite
getCurrentWorkArea() {
96 if (currentLayerId
== null)
97 throw new IllegalStateException("No current layer");
98 return workAreas
.get(currentLayerId
);
101 public String
getCurrentLayerId() {
102 return currentLayerId
;
105 private Composite
getLayer(String id
, Content context
) {
106 if (!layers
.containsKey(id
))
108 if (!workAreas
.containsKey(id
))
109 initLayer(id
, layers
.get(id
), context
);
110 return workAreas
.get(id
);
113 public Composite
switchToLayer(String layerId
, Content context
) {
114 Composite current
= null;
115 if (currentLayerId
!= null) {
116 current
= getCurrentWorkArea();
117 if (currentLayerId
.equals(layerId
))
120 if (context
== null) {
121 if (!getCmsView().isAnonymous())
122 context
= getUserDir();
124 Composite toShow
= getLayer(layerId
, context
);
125 if (toShow
!= null) {
126 currentLayerId
= layerId
;
128 if (!toShow
.isDisposed()) {
129 toShow
.moveAbove(null);
131 log
.warn("Cannot show work area because it is disposed.");
132 toShow
= initLayer(layerId
, layers
.get(layerId
), context
);
133 toShow
.moveAbove(null);
135 dynamicArea
.layout(true, true);
143 public void switchToLayer(SwtAppLayer layer
, Content context
) {
144 // TODO make it more robust
145 for (String layerId
: layers
.keySet()) {
146 SwtAppLayer l
= layers
.get(layerId
);
147 if (layer
.getId().equals(l
.getId())) {
148 switchToLayer(layerId
, context
);
152 throw new IllegalArgumentException("Layer is not registered.");
155 public void addLayer(String id
, SwtAppLayer layer
) {
156 if (!id
.equals(layer
.getId())) {
157 log
.error("Layer id as key '" + id
+ "' is not consistent with layer id '" + layer
.getId()
161 layers
.put(id
, layer
);
164 public void removeLayer(String id
) {
166 if (workAreas
.containsKey(id
)) {
167 Composite workArea
= workAreas
.remove(id
);
168 if (!workArea
.isDisposed())
173 protected Composite
initLayer(String id
, SwtAppLayer layer
, Content context
) {
174 Composite workArea
= getCmsView().doAs(() -> (Composite
) layer
.createUiPart(dynamicArea
, context
));
175 CmsSwtUtils
.style(workArea
, SuiteStyle
.workArea
);
176 workArea
.setLayoutData(CmsSwtUtils
.coverAll());
177 workAreas
.put(id
, workArea
);
181 public synchronized void logout() {
183 currentLayerId
= null;
191 public Composite
getHeader() {
195 public Composite
getFooter() {
199 public Composite
getLeadPane() {
203 public Composite
getSidePane() {
207 public Composite
getBelowHeader() {
211 public Content
getUserDir() {
215 public void setUserDir(Content userDir
) {
216 this.userDir
= userDir
;
220 public Localized
getTitle() {
224 public void setTitle(Localized title
) {
229 public boolean isLoginScreen() {
233 public void setLoginScreen(boolean loginScreen
) {
234 this.loginScreen
= loginScreen
;