]>
git.argeo.org Git - gpl/argeo-suite.git/blob - org/argeo/app/ui/SuiteUi.java
1 package org
.argeo
.app
.ui
;
3 import java
.util
.HashMap
;
6 import org
.argeo
.api
.acr
.Content
;
7 import org
.argeo
.api
.cms
.CmsLog
;
8 import org
.argeo
.cms
.Localized
;
9 import org
.argeo
.cms
.swt
.CmsSwtUi
;
10 import org
.argeo
.cms
.swt
.CmsSwtUtils
;
11 import org
.eclipse
.swt
.SWT
;
12 import org
.eclipse
.swt
.layout
.FormLayout
;
13 import org
.eclipse
.swt
.widgets
.Composite
;
15 /** The view for the default UX of Argeo Suite. */
16 class SuiteUi
extends CmsSwtUi
{
17 private static final long serialVersionUID
= 6207018859086689108L;
18 private final static CmsLog log
= CmsLog
.getLog(SuiteUi
.class);
20 private Localized title
;
21 private Composite header
;
22 private Composite footer
;
23 private Composite belowHeader
;
24 private Composite leadPane
;
25 private Composite sidePane
;
26 private Composite dynamicArea
;
28 private Content userDir
;
30 private Map
<String
, SuiteLayer
> layers
= new HashMap
<>();
31 private Map
<String
, Composite
> workAreas
= new HashMap
<>();
32 private String currentLayerId
= null;
34 private boolean loginScreen
= false;
36 public SuiteUi(Composite parent
, int style
) {
38 this.setLayout(CmsSwtUtils
.noSpaceGridLayout());
40 header
= new Composite(this, SWT
.NONE
);
41 header
.setLayout(CmsSwtUtils
.noSpaceGridLayout());
42 CmsSwtUtils
.style(header
, SuiteStyle
.header
);
43 header
.setLayoutData(CmsSwtUtils
.fillWidth());
45 belowHeader
= new Composite(this, SWT
.NONE
);
46 belowHeader
.setLayoutData(CmsSwtUtils
.fillAll());
48 footer
= new Composite(this, SWT
.NONE
);
49 footer
.setLayout(CmsSwtUtils
.noSpaceGridLayout());
50 CmsSwtUtils
.style(footer
, SuiteStyle
.footer
);
51 footer
.setLayoutData(CmsSwtUtils
.fillWidth());
54 public void refreshBelowHeader(boolean initApp
) {
55 CmsSwtUtils
.clear(belowHeader
);
56 int style
= getStyle();
58 belowHeader
.setLayout(CmsSwtUtils
.noSpaceGridLayout(3));
60 if (SWT
.RIGHT_TO_LEFT
== (style
& SWT
.RIGHT_TO_LEFT
)) {// arabic, hebrew, etc.
61 sidePane
= new Composite(belowHeader
, SWT
.NONE
);
62 sidePane
.setLayout(CmsSwtUtils
.noSpaceGridLayout());
63 sidePane
.setLayoutData(CmsSwtUtils
.fillHeight());
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
);
69 sidePane
= new Composite(belowHeader
, SWT
.NONE
);
70 sidePane
.setLayout(CmsSwtUtils
.noSpaceGridLayout());
71 sidePane
.setLayoutData(CmsSwtUtils
.fillHeight());
73 leadPane
.setLayoutData(CmsSwtUtils
.fillHeight());
74 leadPane
.setLayout(CmsSwtUtils
.noSpaceGridLayout());
75 CmsSwtUtils
.style(leadPane
, SuiteStyle
.leadPane
);
77 dynamicArea
.setLayoutData(CmsSwtUtils
.fillAll());
78 dynamicArea
.setLayout(new FormLayout());
81 belowHeader
.setLayout(CmsSwtUtils
.noSpaceGridLayout());
89 Composite
getCurrentWorkArea() {
90 if (currentLayerId
== null)
91 throw new IllegalStateException("No current layer");
92 return workAreas
.get(currentLayerId
);
95 String
getCurrentLayerId() {
96 return currentLayerId
;
99 private Composite
getLayer(String id
, Content context
) {
100 if (!layers
.containsKey(id
))
102 if (!workAreas
.containsKey(id
))
103 initLayer(id
, layers
.get(id
), context
);
104 return workAreas
.get(id
);
107 Composite
switchToLayer(String layerId
, Content context
) {
108 Composite current
= null;
109 if (currentLayerId
!= null) {
110 current
= getCurrentWorkArea();
111 if (currentLayerId
.equals(layerId
))
114 if (context
== null) {
115 if (!getCmsView().isAnonymous())
116 context
= getUserDir();
118 Composite toShow
= getLayer(layerId
, context
);
119 if (toShow
!= null) {
120 currentLayerId
= layerId
;
122 if (!toShow
.isDisposed()) {
123 toShow
.moveAbove(null);
125 log
.warn("Cannot show work area because it is disposed.");
126 toShow
= initLayer(layerId
, layers
.get(layerId
), context
);
127 toShow
.moveAbove(null);
129 dynamicArea
.layout(true, true);
137 void switchToLayer(SuiteLayer layer
, Content context
) {
138 // TODO make it more robust
139 for (String layerId
: layers
.keySet()) {
140 SuiteLayer l
= layers
.get(layerId
);
141 if (layer
.getId().equals(l
.getId())) {
142 switchToLayer(layerId
, context
);
146 throw new IllegalArgumentException("Layer is not registered.");
149 void addLayer(String id
, SuiteLayer layer
) {
150 layers
.put(id
, layer
);
153 void removeLayer(String id
) {
155 if (workAreas
.containsKey(id
)) {
156 Composite workArea
= workAreas
.remove(id
);
157 if (!workArea
.isDisposed())
162 protected Composite
initLayer(String id
, SuiteLayer layer
, Content context
) {
163 Composite workArea
= getCmsView().doAs(() -> (Composite
) layer
.createUiPart(dynamicArea
, context
));
164 CmsSwtUtils
.style(workArea
, SuiteStyle
.workArea
);
165 workArea
.setLayoutData(CmsSwtUtils
.coverAll());
166 workAreas
.put(id
, workArea
);
170 synchronized void logout() {
172 currentLayerId
= null;
180 Composite
getHeader() {
184 Composite
getFooter() {
188 Composite
getLeadPane() {
192 Composite
getSidePane() {
196 Composite
getBelowHeader() {
200 Content
getUserDir() {
204 void setUserDir(Content userDir
) {
205 this.userDir
= userDir
;
208 public Localized
getTitle() {
212 public void setTitle(Localized title
) {
216 public boolean isLoginScreen() {
220 public void setLoginScreen(boolean loginScreen
) {
221 this.loginScreen
= loginScreen
;