Major refactoring of Argeo CMS UI
[gpl/argeo-suite.git] / org.argeo.suite.ui / src / org / argeo / suite / ui / SuiteUi.java
index d93c3a8b38eb54de555474f13853e6d72646b28b..a79d236b29842c3f38806336a40c6e59f36bdf55 100644 (file)
@@ -11,24 +11,30 @@ import javax.jcr.Session;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.argeo.api.NodeConstants;
-import org.argeo.cms.ui.CmsView;
-import org.argeo.cms.ui.util.CmsUiUtils;
+import org.argeo.api.cms.CmsUi;
+import org.argeo.api.cms.CmsView;
+import org.argeo.cms.Localized;
+import org.argeo.cms.swt.CmsSwtUtils;
 import org.argeo.jcr.Jcr;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.layout.FormLayout;
 import org.eclipse.swt.widgets.Composite;
 
 /** The view for the default ergonomics of Argeo Suite. */
-class SuiteUi extends Composite {
+class SuiteUi extends Composite implements CmsUi {
        private static final long serialVersionUID = 6207018859086689108L;
        private final static Log log = LogFactory.getLog(SuiteUi.class);
+
+       private Localized title;
        private Composite header;
+       private Composite footer;
        private Composite belowHeader;
        private Composite leadPane;
+       private Composite sidePane;
        private Composite dynamicArea;
 
        private Session sysSession;
-//     private Session homeSession;
+       private Session homeSession;
        private Node userDir;
 
        private Map<String, SuiteLayer> layers = new HashMap<>();
@@ -39,38 +45,51 @@ class SuiteUi extends Composite {
 
        public SuiteUi(Composite parent, int style) {
                super(parent, style);
-               cmsView = CmsView.getCmsView(parent);
-               this.setLayout(CmsUiUtils.noSpaceGridLayout());
+               cmsView = CmsSwtUtils.getCmsView(parent);
+               this.setLayout(CmsSwtUtils.noSpaceGridLayout());
 
                header = new Composite(this, SWT.NONE);
-               CmsUiUtils.style(header, SuiteStyle.header);
-               header.setLayoutData(CmsUiUtils.fillWidth());
+               header.setLayout(CmsSwtUtils.noSpaceGridLayout());
+               CmsSwtUtils.style(header, SuiteStyle.header);
+               header.setLayoutData(CmsSwtUtils.fillWidth());
 
                belowHeader = new Composite(this, SWT.NONE);
-               belowHeader.setLayoutData(CmsUiUtils.fillAll());
+               belowHeader.setLayoutData(CmsSwtUtils.fillAll());
+
+               footer = new Composite(this, SWT.NONE);
+               footer.setLayout(CmsSwtUtils.noSpaceGridLayout());
+               CmsSwtUtils.style(footer, SuiteStyle.footer);
+               footer.setLayoutData(CmsSwtUtils.fillWidth());
        }
 
        public void refreshBelowHeader(boolean initApp) {
-               CmsUiUtils.clear(belowHeader);
+               CmsSwtUtils.clear(belowHeader);
                int style = getStyle();
                if (initApp) {
-                       belowHeader.setLayout(CmsUiUtils.noSpaceGridLayout(2));
+                       belowHeader.setLayout(CmsSwtUtils.noSpaceGridLayout(3));
 
                        if (SWT.RIGHT_TO_LEFT == (style & SWT.RIGHT_TO_LEFT)) {// arabic, hebrew, etc.
+                               sidePane = new Composite(belowHeader, SWT.NONE);
+                               sidePane.setLayout(CmsSwtUtils.noSpaceGridLayout());
+                               sidePane.setLayoutData(CmsSwtUtils.fillHeight());
                                dynamicArea = new Composite(belowHeader, SWT.NONE);
                                leadPane = new Composite(belowHeader, SWT.NONE);
                        } else {
                                leadPane = new Composite(belowHeader, SWT.NONE);
                                dynamicArea = new Composite(belowHeader, SWT.NONE);
+                               sidePane = new Composite(belowHeader, SWT.NONE);
+                               sidePane.setLayout(CmsSwtUtils.noSpaceGridLayout());
+                               sidePane.setLayoutData(CmsSwtUtils.fillHeight());
                        }
-                       leadPane.setLayoutData(CmsUiUtils.fillHeight());
-                       CmsUiUtils.style(leadPane, SuiteStyle.leadPane);
-                       dynamicArea.setLayoutData(CmsUiUtils.fillAll());
+                       leadPane.setLayoutData(CmsSwtUtils.fillHeight());
+                       leadPane.setLayout(CmsSwtUtils.noSpaceGridLayout());
+                       CmsSwtUtils.style(leadPane, SuiteStyle.leadPane);
 
+                       dynamicArea.setLayoutData(CmsSwtUtils.fillAll());
                        dynamicArea.setLayout(new FormLayout());
 
                } else {
-                       belowHeader.setLayout(CmsUiUtils.noSpaceGridLayout());
+                       belowHeader.setLayout(CmsSwtUtils.noSpaceGridLayout());
                }
        }
 
@@ -110,14 +129,18 @@ class SuiteUi extends Composite {
                Composite toShow = getLayer(layerId, context);
                if (toShow != null) {
                        currentLayerId = layerId;
-                       if (!isDisposed())
-                               getDisplay().syncExec(() -> {
-                                       if (!toShow.isDisposed())
-                                               toShow.moveAbove(null);
-                                       else
-                                               log.warn("Cannot show work area because it is disposed.");
-                                       dynamicArea.layout(true, true);
-                               });
+                       if (!isDisposed()) {
+//                             getDisplay().syncExec(() -> {
+                               if (!toShow.isDisposed()) {
+                                       toShow.moveAbove(null);
+                               } else {
+                                       log.warn("Cannot show work area because it is disposed.");
+                                       toShow = initLayer(layerId, layers.get(layerId), context);
+                                       toShow.moveAbove(null);
+                               }
+                               dynamicArea.layout(true, true);
+//                             });
+                       }
                        return toShow;
                } else {
                        return current;
@@ -150,7 +173,8 @@ class SuiteUi extends Composite {
 
        protected Composite initLayer(String id, SuiteLayer layer, Node context) {
                Composite workArea = cmsView.doAs(() -> (Composite) layer.createUiPart(dynamicArea, context));
-               workArea.setLayoutData(CmsUiUtils.coverAll());
+               CmsSwtUtils.style(workArea, SuiteStyle.workArea);
+               workArea.setLayoutData(CmsSwtUtils.coverAll());
                workAreas.put(id, workArea);
                return workArea;
        }
@@ -158,7 +182,7 @@ class SuiteUi extends Composite {
        synchronized void logout() {
                userDir = null;
                Jcr.logout(sysSession);
-//             Jcr.logout(homeSession);
+               Jcr.logout(homeSession);
                currentLayerId = null;
                workAreas.clear();
        }
@@ -171,10 +195,18 @@ class SuiteUi extends Composite {
                return header;
        }
 
+       Composite getFooter() {
+               return footer;
+       }
+
        Composite getLeadPane() {
                return leadPane;
        }
 
+       Composite getSidePane() {
+               return sidePane;
+       }
+
        Composite getBelowHeader() {
                return belowHeader;
        }
@@ -185,11 +217,11 @@ class SuiteUi extends Composite {
 //
        synchronized void initSessions(Repository repository, String userDirPath) throws RepositoryException {
                this.sysSession = repository.login();
-//             this.homeSession = repository.login(NodeConstants.HOME_WORKSPACE);
+               this.homeSession = repository.login(NodeConstants.HOME_WORKSPACE);
                userDir = sysSession.getNode(userDirPath);
                addDisposeListener((e) -> {
                        Jcr.logout(sysSession);
-//                     Jcr.logout(homeSession);
+                       Jcr.logout(homeSession);
                });
        }
 
@@ -206,8 +238,8 @@ class SuiteUi extends Composite {
                        return sysSession;
                if (NodeConstants.SYS_WORKSPACE.equals(workspaceName))
                        return sysSession;
-//             else if (NodeConstants.HOME_WORKSPACE.equals(workspaceName))
-//                     return homeSession;
+               else if (NodeConstants.HOME_WORKSPACE.equals(workspaceName))
+                       return homeSession;
                else
                        throw new IllegalArgumentException("Unknown workspace " + workspaceName);
        }
@@ -216,4 +248,12 @@ class SuiteUi extends Composite {
                return cmsView;
        }
 
+       public Localized getTitle() {
+               return title;
+       }
+
+       public void setTitle(Localized title) {
+               this.title = title;
+       }
+
 }