Better script support in CMS.
authorMathieu Baudier <mbaudier@argeo.org>
Thu, 4 Oct 2018 16:56:02 +0000 (18:56 +0200)
committerMathieu Baudier <mbaudier@argeo.org>
Thu, 4 Oct 2018 16:56:02 +0000 (18:56 +0200)
More side areas in simple ergonomy.

18 files changed:
org.argeo.cms.e4.rap/OSGI-INF/cms-admin-rap.xml
org.argeo.cms.e4.rap/OSGI-INF/cms-demo-rap.xml
org.argeo.cms.e4.rap/bnd.bnd
org.argeo.cms.e4.rap/cms/app.js [new file with mode: 0644]
org.argeo.cms.e4.rap/src/org/argeo/cms/e4/rap/CmsE4EntryPointFactory.java
org.argeo.cms.ui/src/org/argeo/cms/script/AppUi.java
org.argeo.cms.ui/src/org/argeo/cms/script/CmsScriptApp.java
org.argeo.cms.ui/src/org/argeo/cms/script/Theme.java
org.argeo.cms.ui/src/org/argeo/cms/script/cms.js
org.argeo.cms.ui/src/org/argeo/cms/ui/AbstractCmsEntryPoint.java
org.argeo.cms.ui/src/org/argeo/cms/ui/CmsStyles.java
org.argeo.cms.ui/src/org/argeo/cms/util/CmsLink.java
org.argeo.cms.ui/src/org/argeo/cms/util/CmsPane.java
org.argeo.cms.ui/src/org/argeo/cms/util/MenuLink.java
org.argeo.cms.ui/src/org/argeo/cms/util/SimpleCmsHeader.java
org.argeo.cms.ui/src/org/argeo/cms/util/SimpleErgonomics.java
org.argeo.cms.ui/src/org/argeo/cms/util/VerticalMenu.java [new file with mode: 0644]
org.argeo.cms.ui/src/org/argeo/cms/widgets/auth/CmsLogin.java

index 1f688baa6f6efab32c8e7aa1391a2b19d0d7c644..26b454a7e3352ab41c7714d0a889708c3e438fa3 100644 (file)
@@ -3,6 +3,6 @@
    <implementation class="org.argeo.cms.e4.rap.CmsE4AdminApp"/>
    <service>
       <provide interface="org.eclipse.rap.rwt.application.ApplicationConfiguration"/>
-      <property name="contextName" type="String" value="cms"/>
+      <property name="contextName" type="String" value="cmsXXX"/>
    </service>
 </scr:component>
index 2fa018276898ef1c9d39bd2ab7346f1c29afc63f..e23b11b6ab344aa550b204740fb1c86aed90b0ef 100644 (file)
@@ -3,6 +3,6 @@
    <implementation class="org.argeo.cms.e4.rap.CmsE4DemoApp"/>
    <service>
       <provide interface="org.eclipse.rap.rwt.application.ApplicationConfiguration"/>
-      <property name="contextName" type="String" value="demo"/>
+      <property name="contextName" type="String" value="demoXXX"/>
    </service>
 </scr:component>
index 53aa941930771b5816e7d61f163d19bfcfc94f06..61e39b09f9c5c39736ad401823815c539efe7143 100644 (file)
@@ -2,9 +2,12 @@ Bundle-ActivationPolicy: lazy
 Service-Component: OSGI-INF/cms-admin-rap.xml,\
 OSGI-INF/cms-demo-rap.xml
 
+Bundle-Activator: org.argeo.cms.script.ScriptAppActivator
+
 Import-Package: org.argeo.node,\
 org.eclipse.swt,\
 org.eclipse.swt.graphics,\
 org.eclipse.e4.ui.workbench,\
 org.eclipse.rap.rwt.client,\
+org.argeo.cms.script,\
 *
diff --git a/org.argeo.cms.e4.rap/cms/app.js b/org.argeo.cms.e4.rap/cms/app.js
new file mode 100644 (file)
index 0000000..d4c9045
--- /dev/null
@@ -0,0 +1,8 @@
+// Standard CMS App
+APP.webPath = 'cms'
+
+// Common
+APP.pageTitle = 'Argeo CMS';
+
+APP.ui['devops'] = new org.argeo.cms.script.AppUi(APP, new org.argeo.cms.e4.rap.CmsE4EntryPointFactory('org.argeo.cms.e4/e4xmi/cms-devops.e4xmi'));
+APP.ui['devops'].pageTitle = 'Argeo CMS DevOps';
index e3490002dd3976cabe1e4bc0e67075e9856630a1..a5a32348e43896837bd0908730af7a4aa4fc0dba 100644 (file)
@@ -11,11 +11,25 @@ import org.eclipse.rap.rwt.application.EntryPoint;
 import org.eclipse.rap.rwt.client.service.JavaScriptExecutor;
 
 public class CmsE4EntryPointFactory extends E4EntryPointFactory {
+       public final static String DEFAULT_LIFECYCLE_URI = "bundleclass://org.argeo.cms.e4.rap/org.argeo.cms.e4.rap.CmsLoginLifecycle";
 
        public CmsE4EntryPointFactory(E4ApplicationConfig config) {
                super(config);
        }
 
+       public CmsE4EntryPointFactory(String e4Xmi, String lifeCycleUri) {
+               super(defaultConfig(e4Xmi, lifeCycleUri));
+       }
+
+       public CmsE4EntryPointFactory(String e4Xmi) {
+               this(e4Xmi, DEFAULT_LIFECYCLE_URI);
+       }
+
+       public static E4ApplicationConfig defaultConfig(String e4Xmi, String lifeCycleUri) {
+               E4ApplicationConfig config = new E4ApplicationConfig(e4Xmi, lifeCycleUri, null, null, false, true, true);
+               return config;
+       }
+
        @Override
        public EntryPoint create() {
                EntryPoint ep = createEntryPoint();
@@ -59,98 +73,4 @@ public class CmsE4EntryPointFactory extends E4EntryPointFactory {
        protected EntryPoint createEntryPoint() {
                return super.create();
        }
-
-       // private boolean login(Subject subject) {
-       // Display display = new Display();
-       // CmsView cmsView = new E4CmsView(subject);
-       // CmsLoginShell loginShell = new CmsLoginShell(cmsView);
-       // loginShell.setSubject(subject);
-       // try {
-       // // try pre-auth
-       // LoginContext loginContext = new
-       // LoginContext(NodeConstants.LOGIN_CONTEXT_USER, subject, loginShell);
-       // loginContext.login();
-       // } catch (LoginException e) {
-       // loginShell.createUi();
-       // loginShell.open();
-       //
-       // while (!loginShell.getShell().isDisposed()) {
-       // if (!display.readAndDispatch())
-       // display.sleep();
-       // }
-       // } finally {
-       // display.dispose();
-       // }
-       // if (CurrentUser.getUsername(subject) == null)
-       // return false;
-       // return true;
-       // }
-       //
-       // private class E4CmsView implements CmsView {
-       // private LoginContext loginContext;
-       // private UxContext uxContext;
-       // private Subject subject;
-       //
-       // public E4CmsView(Subject subject) {
-       // this.subject = subject;
-       // uxContext = new SimpleUxContext();
-       // }
-       //
-       // @Override
-       // public UxContext getUxContext() {
-       // return uxContext;
-       // }
-       //
-       // @Override
-       // public void navigateTo(String state) {
-       // // TODO Auto-generated method stub
-       //
-       // }
-       //
-       // @Override
-       // public void authChange(LoginContext loginContext) {
-       // if (loginContext == null)
-       // throw new CmsException("Login context cannot be null");
-       // // logout previous login context
-       // // if (this.loginContext != null)
-       // // try {
-       // // this.loginContext.logout();
-       // // } catch (LoginException e1) {
-       // // System.err.println("Could not log out: " + e1);
-       // // }
-       // this.loginContext = loginContext;
-       // }
-       //
-       // @Override
-       // public void logout() {
-       // if (loginContext == null)
-       // throw new CmsException("Login context should not bet null");
-       // try {
-       // CurrentUser.logoutCmsSession(loginContext.getSubject());
-       // loginContext.logout();
-       // } catch (LoginException e) {
-       // throw new CmsException("Cannot log out", e);
-       // }
-       // }
-       //
-       // @Override
-       // public void exception(Throwable e) {
-       // log.error("Unexpected exception in Eclipse 4 RAP", e);
-       // }
-       //
-       // @Override
-       // public CmsImageManager getImageManager() {
-       // // TODO Auto-generated method stub
-       // return null;
-       // }
-       //
-       // protected Subject getSubject() {
-       // return subject;
-       // }
-       //
-       // @Override
-       // public boolean isAnonymous() {
-       // return CurrentUser.isAnonymous(getSubject());
-       // }
-       // }
 }
index cea57df8949bd0323d2ccd46e087e9b78c68ae43..e0b2a883fcf173aa80c560d61f560bdc79625c3f 100644 (file)
@@ -37,6 +37,8 @@ public class AppUi implements CmsUiProvider, Branding {
        private String script;
        // private Branding branding = new Branding();
 
+       private EntryPointFactory factory;
+
        // Branding
        private String themeId;
        private String additionalHeaders;
@@ -59,20 +61,36 @@ public class AppUi implements CmsUiProvider, Branding {
                this.ui = uiProvider;
        }
 
+       public AppUi(CmsScriptApp app, EntryPointFactory factory) {
+               this.app = app;
+               this.factory = factory;
+       }
+
        public void apply(Repository repository, Application application, Branding appBranding, String path) {
                Map<String, String> factoryProperties = new HashMap<>();
                if (appBranding != null)
                        appBranding.applyBranding(factoryProperties);
                applyBranding(factoryProperties);
-               EntryPointFactory entryPointFactory = new EntryPointFactory() {
-                       @Override
-                       public EntryPoint create() {
-                               SimpleErgonomics ergonomics = new SimpleErgonomics(repository, "main", "/home/root/argeo:keyring",
-                                               AppUi.this, factoryProperties);
-                               return ergonomics;
-                       }
-               };
-               application.addEntryPoint("/" + path, entryPointFactory, factoryProperties);
+               if (factory != null) {
+                       application.addEntryPoint("/" + path, factory, factoryProperties);
+               } else {
+                       EntryPointFactory entryPointFactory = new EntryPointFactory() {
+                               @Override
+                               public EntryPoint create() {
+                                       SimpleErgonomics ergonomics = new SimpleErgonomics(repository, "main", "/home/root/argeo:keyring",
+                                                       AppUi.this, factoryProperties);
+//                                     CmsUiProvider header = app.getHeader();
+//                                     if (header != null)
+//                                             ergonomics.setHeader(header);
+                                       app.applySides(ergonomics);
+                                       Integer headerHeight = app.getHeaderHeight();
+                                       if (headerHeight != null)
+                                               ergonomics.setHeaderHeight(headerHeight);
+                                       return ergonomics;
+                               }
+                       };
+                       application.addEntryPoint("/" + path, entryPointFactory, factoryProperties);
+               }
        }
 
        public void setUi(CmsUiProvider uiProvider) {
@@ -101,31 +119,35 @@ public class AppUi implements CmsUiProvider, Branding {
        @Override
        public Control createUi(Composite parent, Node context) throws RepositoryException {
                CmsPane cmsPane = new CmsPane(parent, SWT.NONE);
-               // QA
-               CmsUtils.style(cmsPane.getQaArea(), "qa");
-               Button reload = new Button(cmsPane.getQaArea(), SWT.FLAT);
-               CmsUtils.style(reload, "qa");
-               reload.setText("Reload");
-               reload.addSelectionListener(new Selected() {
-                       private static final long serialVersionUID = 1L;
-
-                       @Override
-                       public void widgetSelected(SelectionEvent e) {
-                               new Thread() {
-                                       @Override
-                                       public void run() {
-                                               app.reload();
-                                       }
-                               }.start();
-                               RWT.getClient().getService(JavaScriptExecutor.class).execute("setTimeout('location.reload()',1000)");
-                       }
-               });
 
-               // Support
-               CmsUtils.style(cmsPane.getSupportArea(), "support");
-               Label msg = new Label(cmsPane.getSupportArea(), SWT.NONE);
-               CmsUtils.style(msg, "support");
-               msg.setText("UNSUPPORTED DEVELOPMENT VERSION");
+               if (false) {
+                       // QA
+                       CmsUtils.style(cmsPane.getQaArea(), "qa");
+                       Button reload = new Button(cmsPane.getQaArea(), SWT.FLAT);
+                       CmsUtils.style(reload, "qa");
+                       reload.setText("Reload");
+                       reload.addSelectionListener(new Selected() {
+                               private static final long serialVersionUID = 1L;
+
+                               @Override
+                               public void widgetSelected(SelectionEvent e) {
+                                       new Thread() {
+                                               @Override
+                                               public void run() {
+                                                       app.reload();
+                                               }
+                                       }.start();
+                                       RWT.getClient().getService(JavaScriptExecutor.class)
+                                                       .execute("setTimeout('location.reload()',1000)");
+                               }
+                       });
+
+                       // Support
+                       CmsUtils.style(cmsPane.getSupportArea(), "support");
+                       Label msg = new Label(cmsPane.getSupportArea(), SWT.NONE);
+                       CmsUtils.style(msg, "support");
+                       msg.setText("UNSUPPORTED DEVELOPMENT VERSION");
+               }
 
                if (ui != null) {
                        ui.createUi(cmsPane.getMainArea(), context);
index e6ccf52a7567b8a2056ab653d1fc11c6f9834414..2425374a0e56052cdc7223aa94979bd9b714ff8a 100644 (file)
@@ -20,8 +20,10 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.argeo.cms.CmsException;
 import org.argeo.cms.ui.CmsConstants;
+import org.argeo.cms.ui.CmsUiProvider;
 import org.argeo.cms.util.BundleResourceLoader;
 import org.argeo.cms.util.CmsUtils;
+import org.argeo.cms.util.SimpleErgonomics;
 import org.eclipse.rap.rwt.application.Application;
 import org.eclipse.rap.rwt.application.Application.OperationMode;
 import org.eclipse.rap.rwt.application.ApplicationConfiguration;
@@ -50,6 +52,12 @@ public class CmsScriptApp implements Branding {
 
        private Map<String, AppUi> ui = new HashMap<>();
 
+       private CmsUiProvider header;
+       private Integer headerHeight = null;
+       private CmsUiProvider lead;
+       private CmsUiProvider end;
+       private CmsUiProvider footer;
+
        // Branding
        private String themeId;
        private String additionalHeaders;
@@ -101,6 +109,13 @@ public class CmsScriptApp implements Branding {
 
        }
 
+       public void applySides(SimpleErgonomics simpleErgonomics) {
+               simpleErgonomics.setHeader(header);
+               simpleErgonomics.setLead(lead);
+               simpleErgonomics.setEnd(end);
+               simpleErgonomics.setFooter(footer);
+       }
+
        public void register(BundleContext bundleContext, ApplicationConfiguration appConfig) {
                Hashtable<String, String> props = new Hashtable<>();
                props.put(CONTEXT_NAME, webPath);
@@ -301,4 +316,44 @@ public class CmsScriptApp implements Branding {
                this.favicon = favicon;
        }
 
+       public CmsUiProvider getHeader() {
+               return header;
+       }
+
+       public void setHeader(CmsUiProvider header) {
+               this.header = header;
+       }
+
+       public Integer getHeaderHeight() {
+               return headerHeight;
+       }
+
+       public void setHeaderHeight(Integer headerHeight) {
+               this.headerHeight = headerHeight;
+       }
+
+       public CmsUiProvider getLead() {
+               return lead;
+       }
+
+       public void setLead(CmsUiProvider lead) {
+               this.lead = lead;
+       }
+
+       public CmsUiProvider getEnd() {
+               return end;
+       }
+
+       public void setEnd(CmsUiProvider end) {
+               this.end = end;
+       }
+
+       public CmsUiProvider getFooter() {
+               return footer;
+       }
+
+       public void setFooter(CmsUiProvider footer) {
+               this.footer = footer;
+       }
+
 }
index 51fc65ddab7f6d37cf1327443690d488dab2200c..2f1ed0efe7d44e02759caa8c499b3660c2f7c85d 100644 (file)
@@ -26,16 +26,32 @@ import org.osgi.framework.BundleContext;
 public class Theme {
        private final static Log log = LogFactory.getLog(Theme.class);
 
-       private String themeId;
+       private final String themeId;
        private Map<String, ResourceLoader> css = new HashMap<>();
        private Map<String, ResourceLoader> resources = new HashMap<>();
 
        private String headerCss;
        private List<String> fonts = new ArrayList<>();
 
+       private String basePath;
+       private String cssPath;
+
+       public Theme(BundleContext bundleContext) {
+               this(bundleContext, null);
+       }
+
        public Theme(BundleContext bundleContext, String symbolicName) {
-               this.themeId = symbolicName;
-               Bundle themeBundle = ThemeUtils.findThemeBundle(bundleContext, symbolicName);
+               Bundle themeBundle;
+               if (symbolicName == null) {
+                       themeBundle = bundleContext.getBundle();
+                       basePath = "/theme/internal/";
+                       cssPath = basePath;
+               } else {
+                       themeBundle = ThemeUtils.findThemeBundle(bundleContext, symbolicName);
+                       basePath = "/";
+                       cssPath = "/rap/";
+               }
+               this.themeId = themeBundle.getSymbolicName();
                addStyleSheets(themeBundle, new BundleResourceLoader(themeBundle));
                BundleResourceLoader themeBRL = new BundleResourceLoader(themeBundle);
                addResources(themeBRL, "*.png");
@@ -46,13 +62,13 @@ public class Theme {
                addResources(themeBRL, "*.ico");
 
                // fonts
-               URL fontsUrl = themeBundle.getEntry("fonts.txt");
+               URL fontsUrl = themeBundle.getEntry(basePath + "fonts.txt");
                if (fontsUrl != null) {
                        loadFontsUrl(fontsUrl);
                }
 
                // common CSS header (plain CSS)
-               URL headerCssUrl = themeBundle.getEntry("header.css");
+               URL headerCssUrl = themeBundle.getEntry(basePath + "header.css");
                if (headerCssUrl != null) {
                        try (BufferedReader buffer = new BufferedReader(new InputStreamReader(headerCssUrl.openStream(), UTF_8))) {
                                headerCss = buffer.lines().collect(Collectors.joining("\n"));
@@ -91,7 +107,7 @@ public class Theme {
        }
 
        void addStyleSheets(Bundle themeBundle, ResourceLoader ssRL) {
-               Enumeration<URL> themeResources = themeBundle.findEntries("/rap", "*.css", true);
+               Enumeration<URL> themeResources = themeBundle.findEntries(cssPath, "*.css", true);
                if (themeResources == null)
                        return;
                while (themeResources.hasMoreElements()) {
@@ -124,7 +140,7 @@ public class Theme {
 
        void addResources(BundleResourceLoader themeBRL, String pattern) {
                Bundle themeBundle = themeBRL.getBundle();
-               Enumeration<URL> themeResources = themeBundle.findEntries("/", pattern, true);
+               Enumeration<URL> themeResources = themeBundle.findEntries(basePath, pattern, true);
                if (themeResources == null)
                        return;
                while (themeResources.hasMoreElements()) {
@@ -145,4 +161,20 @@ public class Theme {
                return themeId;
        }
 
+       public String getBasePath() {
+               return basePath;
+       }
+
+       public void setBasePath(String basePath) {
+               this.basePath = basePath;
+       }
+
+       public String getCssPath() {
+               return cssPath;
+       }
+
+       public void setCssPath(String cssPath) {
+               this.cssPath = cssPath;
+       }
+
 }
index 2ffcf9e751b6a374bfaeae44b623d3a5fe50d4c0..2005b4ce868d10894adbaa55250f358945b52bd8 100644 (file)
@@ -1,9 +1,13 @@
-//var CmsUiProvider = Java.type('org.argeo.cms.ui.CmsUiProvider');
+// CMS
 var CmsScriptApp = Java.type('org.argeo.cms.script.CmsScriptApp');
 var AppUi = Java.type('org.argeo.cms.script.AppUi');
 var Theme = Java.type('org.argeo.cms.script.Theme');
 var ScriptUi = Java.type('org.argeo.cms.script.ScriptUi');
 var CmsUtils = Java.type('org.argeo.cms.util.CmsUtils');
+var SimpleCmsHeader = Java.type('org.argeo.cms.util.SimpleCmsHeader');
+var CmsLink = Java.type('org.argeo.cms.util.CmsLink');
+var MenuLink = Java.type('org.argeo.cms.util.MenuLink');
+var UserMenuLink = Java.type('org.argeo.cms.util.UserMenuLink');
 
 // SWT
 var SWT = Java.type('org.eclipse.swt.SWT');
index 5c59d601bd4996a00841afe6b4a6b26468448f32..529061e92f0f96229a646cae83a9d7057140adb8 100644 (file)
@@ -302,8 +302,10 @@ public abstract class AbstractCmsEntryPoint extends AbstractEntryPoint implement
                                Node newNode = null;
                                if (session.nodeExists(newNodePath))
                                        newNode = session.getNode(newNodePath);
-                               else
-                                       throw new CmsException("Data " + newNodePath + " does not exist");
+                               else {
+//                                     throw new CmsException("Data " + newNodePath + " does not exist");
+                                       newNode = null;
+                               }
                                setNode(newNode);
                        }
                        String title = publishMetaData(getNode());
@@ -326,7 +328,7 @@ public abstract class AbstractCmsEntryPoint extends AbstractEntryPoint implement
        private String publishMetaData(Node node) throws RepositoryException {
                // Title
                String title;
-               if (node.isNodeType(NodeType.MIX_TITLE) && node.hasProperty(Property.JCR_TITLE))
+               if (node!=null && node.isNodeType(NodeType.MIX_TITLE) && node.hasProperty(Property.JCR_TITLE))
                        title = node.getProperty(Property.JCR_TITLE).getString() + " - " + getBaseTitle();
                else
                        title = getBaseTitle();
index 2df1ea03157ed2ea52e7f8553e92ccf92c0c020d..506e971ccb14191b131e9c315b0a13dd0ad509e3 100644 (file)
@@ -11,6 +11,11 @@ public interface CmsStyles {
        public final static String CMS_HEADER_LEAD = "cms_header-lead";
        public final static String CMS_HEADER_CENTER = "cms_header-center";
        public final static String CMS_HEADER_END = "cms_header-end";
+
+       public final static String CMS_LEAD = "cms_lead";
+       public final static String CMS_END = "cms_end";
+       public final static String CMS_FOOTER = "cms_footer";
+
        public final static String CMS_USER_MENU = "cms_user_menu";
        public final static String CMS_USER_MENU_LINK = "cms_user_menu-link";
        public final static String CMS_USER_MENU_ITEM = "cms_user_menu-item";
index 7c51e2ead877c08ad1287b3fdf0059a038aded05..faf01182b82c4d66ea1210b3ea88d5a378c5cacf 100644 (file)
@@ -37,6 +37,7 @@ public class CmsLink implements CmsUiProvider {
        private String image;
        private MouseListener mouseListener;
 
+       private int horizontalAlignment = SWT.CENTER;
        private int verticalAlignment = SWT.CENTER;
 
        private String loggedInLabel = null;
@@ -65,29 +66,37 @@ public class CmsLink implements CmsUiProvider {
        public void init() {
                if (image != null) {
                        ImageData image = loadImage();
-                       imageWidth = image.width;
-                       imageHeight = image.height;
+                       if (imageHeight == null && imageWidth == null) {
+                               imageWidth = image.width;
+                               imageHeight = image.height;
+                       } else if (imageHeight == null) {
+                               imageHeight = (imageWidth * image.height) / image.width;
+                       } else if (imageWidth == null) {
+                               imageWidth = (imageHeight * image.width) / image.height;
+                       }
                }
        }
 
        /** @return {@link Composite} with a single {@link Label} child. */
        @Override
        public Control createUi(final Composite parent, Node context) {
-               if (image != null && (imageWidth == null || imageHeight == null)) {
-                       throw new CmsException("Image is not properly configured."
-                                       + " Make sure bundleContext property is set and init() method has been called.");
-               }
+//             if (image != null && (imageWidth == null || imageHeight == null)) {
+//                     throw new CmsException("Image is not properly configured."
+//                                     + " Make sure bundleContext property is set and init() method has been called.");
+//             }
 
                Composite comp = new Composite(parent, SWT.BOTTOM);
                comp.setLayout(CmsUtils.noSpaceGridLayout());
 
                Label link = new Label(comp, SWT.NONE);
                link.setData(RWT.MARKUP_ENABLED, Boolean.TRUE);
-               GridData layoutData = new GridData(SWT.CENTER, verticalAlignment, true, true);
+               GridData layoutData = new GridData(horizontalAlignment, verticalAlignment, false, false);
                if (image != null) {
-                       layoutData.heightHint = imageHeight;
+                       if (imageHeight != null)
+                               layoutData.heightHint = imageHeight;
                        if (label == null)
-                               layoutData.widthHint = imageWidth;
+                               if (imageWidth != null)
+                                       layoutData.widthHint = imageWidth;
                }
 
                link.setLayoutData(layoutData);
@@ -123,8 +132,12 @@ public class CmsLink implements CmsUiProvider {
                if (image != null) {
                        registerImageIfNeeded();
                        String imageLocation = RWT.getResourceManager().getLocation(image);
-                       labelText.append("<img width='").append(imageWidth).append("' height='").append(imageHeight)
-                                       .append("' src=\"").append(imageLocation).append("\"/>");
+                       labelText.append("<img");
+                       if (imageWidth != null)
+                               labelText.append(" width='").append(imageWidth).append('\'');
+                       if (imageHeight != null)
+                               labelText.append(" height='").append(imageHeight).append('\'');
+                       labelText.append(" src=\"").append(imageLocation).append("\"/>");
 
                }
 
@@ -250,4 +263,12 @@ public class CmsLink implements CmsUiProvider {
                return !CurrentUser.isAnonymous();
        }
 
+       public void setImageWidth(Integer imageWidth) {
+               this.imageWidth = imageWidth;
+       }
+
+       public void setImageHeight(Integer imageHeight) {
+               this.imageHeight = imageHeight;
+       }
+
 }
index f64768df7dd4820218e0214ac461ebbe4f258d98..a8d085cfe688ca117717ddf62ab9d568668429d2 100644 (file)
@@ -16,21 +16,21 @@ public class CmsPane {
        public CmsPane(Composite parent, int style) {
                parent.setLayout(CmsUtils.noSpaceGridLayout());
 
-               qaArea = new Composite(parent, SWT.NONE);
-               qaArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
-               RowLayout qaLayout = new RowLayout();
-               qaLayout.spacing = 0;
-               qaArea.setLayout(qaLayout);
+//             qaArea = new Composite(parent, SWT.NONE);
+//             qaArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+//             RowLayout qaLayout = new RowLayout();
+//             qaLayout.spacing = 0;
+//             qaArea.setLayout(qaLayout);
 
                mainArea = new Composite(parent, SWT.NONE);
                mainArea.setLayout(new GridLayout());
                mainArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
 
-               supportArea = new Composite(parent, SWT.NONE);
-               supportArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
-               RowLayout supportLayout = new RowLayout();
-               supportLayout.spacing = 0;
-               supportArea.setLayout(supportLayout);
+//             supportArea = new Composite(parent, SWT.NONE);
+//             supportArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+//             RowLayout supportLayout = new RowLayout();
+//             supportLayout.spacing = 0;
+//             supportArea.setLayout(supportLayout);
        }
 
        public Composite getMainArea() {
index c91674d7b2ede0844ee72ea5d34b046a13dfb812..79fd7cb72ea3b4c75013f1c4b35cb5cb1129aee9 100644 (file)
@@ -10,4 +10,13 @@ public class MenuLink extends CmsLink {
        public MenuLink() {
                setCustom(CmsStyles.CMS_MENU_LINK);
        }
+
+       public MenuLink(String label, String target, String custom) {
+               super(label, target, custom);
+       }
+
+       public MenuLink(String label, String target) {
+               super(label, target, CmsStyles.CMS_MENU_LINK);
+       }
+
 }
index 3f79c7fffea16e61a9a861b7688c050b15010797..ae1299dc8daacd4a92a25ce44fb7ca0c2d556905 100644 (file)
@@ -25,8 +25,7 @@ public class SimpleCmsHeader implements CmsUiProvider {
        private Boolean subPartsSameWidth = false;
 
        @Override
-       public Control createUi(Composite parent, Node context)
-                       throws RepositoryException {
+       public Control createUi(Composite parent, Node context) throws RepositoryException {
                Composite header = new Composite(parent, SWT.NONE);
                header.setData(RWT.CUSTOM_VARIANT, CmsStyles.CMS_HEADER);
                header.setBackgroundMode(SWT.INHERIT_DEFAULT);
@@ -38,8 +37,8 @@ public class SimpleCmsHeader implements CmsUiProvider {
                return header;
        }
 
-       protected void configurePart(Node context, Composite parent,
-                       List<CmsUiProvider> partProviders) throws RepositoryException {
+       protected void configurePart(Node context, Composite parent, List<CmsUiProvider> partProviders)
+                       throws RepositoryException {
                final int style;
                final String custom;
                if (lead == partProviders) {
@@ -52,20 +51,17 @@ public class SimpleCmsHeader implements CmsUiProvider {
                        style = SWT.END;
                        custom = CmsStyles.CMS_HEADER_END;
                } else {
-                       throw new CmsException("Unsupported part providers "
-                                       + partProviders);
+                       throw new CmsException("Unsupported part providers " + partProviders);
                }
 
                Composite part = new Composite(parent, SWT.NONE);
                part.setData(RWT.CUSTOM_VARIANT, custom);
                GridData gridData = new GridData(style, SWT.FILL, true, true);
                part.setLayoutData(gridData);
-               part.setLayout(CmsUtils.noSpaceGridLayout(new GridLayout(partProviders
-                               .size(), subPartsSameWidth)));
+               part.setLayout(CmsUtils.noSpaceGridLayout(new GridLayout(partProviders.size(), subPartsSameWidth)));
                for (CmsUiProvider uiProvider : partProviders) {
                        Control subPart = uiProvider.createUi(part, context);
-                       subPart.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
-                                       true));
+                       subPart.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
                }
        }
 
@@ -85,4 +81,16 @@ public class SimpleCmsHeader implements CmsUiProvider {
                this.subPartsSameWidth = subPartsSameWidth;
        }
 
+       public List<CmsUiProvider> getLead() {
+               return lead;
+       }
+
+       public List<CmsUiProvider> getCenter() {
+               return center;
+       }
+
+       public List<CmsUiProvider> getEnd() {
+               return end;
+       }
+
 }
index 37464079155e3a4097325ae656f5b82d4c024997..de6ce1c59ff9893dc61d8489ab22322f27f895ff 100644 (file)
@@ -19,6 +19,7 @@ import org.eclipse.rap.rwt.RWT;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.layout.FillLayout;
 import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
 
@@ -30,11 +31,17 @@ public class SimpleErgonomics extends AbstractCmsEntryPoint {
 
        private boolean uiInitialized = false;
        private Composite headerArea;
+       private Composite leftArea;
+       private Composite rightArea;
+       private Composite footerArea;
        private Composite bodyArea;
        private final CmsUiProvider uiProvider;
 
        private CmsUiProvider header;
        private Integer headerHeight = 0;
+       private CmsUiProvider lead;
+       private CmsUiProvider end;
+       private CmsUiProvider footer;
 
        private CmsImageManager imageManager = new ImageManagerImpl();
        private UxContext uxContext = null;
@@ -48,21 +55,38 @@ public class SimpleErgonomics extends AbstractCmsEntryPoint {
        @Override
        protected void initUi(Composite parent) {
                parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
-               parent.setLayout(CmsUtils.noSpaceGridLayout());
+               parent.setLayout(CmsUtils.noSpaceGridLayout(new GridLayout(3, false)));
 
                uxContext = new SimpleUxContext();
                if (!getUxContext().isMasterData())
                        createAdminArea(parent);
                headerArea = new Composite(parent, SWT.NONE);
                headerArea.setLayout(new FillLayout());
-               GridData headerData = new GridData(SWT.FILL, SWT.FILL, false, false);
+               GridData headerData = new GridData(SWT.FILL, SWT.FILL, false, false, 3, 1);
                headerData.heightHint = headerHeight;
                headerArea.setLayoutData(headerData);
 
+               // TODO: bi-directional
+               leftArea = new Composite(parent, SWT.NONE);
+               leftArea.setLayoutData(new GridData(SWT.LEAD, SWT.TOP, false, false));
+               leftArea.setLayout(CmsUtils.noSpaceGridLayout());
+
                bodyArea = new Composite(parent, SWT.NONE);
                bodyArea.setData(RWT.CUSTOM_VARIANT, CmsStyles.CMS_BODY);
                bodyArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
                bodyArea.setLayout(CmsUtils.noSpaceGridLayout());
+
+               // TODO: bi-directional
+               rightArea = new Composite(parent, SWT.NONE);
+               rightArea.setLayoutData(new GridData(SWT.END, SWT.TOP, false, false));
+               rightArea.setLayout(CmsUtils.noSpaceGridLayout());
+
+               footerArea = new Composite(parent, SWT.NONE);
+               // footerArea.setLayout(new FillLayout());
+               GridData footerData = new GridData(SWT.FILL, SWT.FILL, false, false, 3, 1);
+               footerData.heightHint = headerHeight;
+               footerArea.setLayoutData(footerData);
+
                uiInitialized = true;
                refresh();
        }
@@ -73,7 +97,7 @@ public class SimpleErgonomics extends AbstractCmsEntryPoint {
                        return;
                if (getState() == null)
                        setState("");
-               refreshHeader();
+               refreshSides();
                refreshBody();
                if (log.isTraceEnabled())
                        log.trace("UI refreshed " + getNode());
@@ -82,6 +106,7 @@ public class SimpleErgonomics extends AbstractCmsEntryPoint {
        protected void createAdminArea(Composite parent) {
        }
 
+       @Deprecated
        protected void refreshHeader() {
                if (header == null)
                        return;
@@ -96,6 +121,28 @@ public class SimpleErgonomics extends AbstractCmsEntryPoint {
                headerArea.layout(true, true);
        }
 
+       protected void refreshSides() {
+               refresh(headerArea, header, CmsStyles.CMS_HEADER);
+               refresh(leftArea, lead, CmsStyles.CMS_LEAD);
+               refresh(rightArea, end, CmsStyles.CMS_END);
+               refresh(footerArea, footer, CmsStyles.CMS_FOOTER);
+       }
+
+       private void refresh(Composite area, CmsUiProvider uiProvider, String style) {
+               if (uiProvider == null)
+                       return;
+
+               for (Control child : area.getChildren())
+                       child.dispose();
+               CmsUtils.style(area, style);
+               try {
+                       uiProvider.createUi(area, getNode());
+               } catch (RepositoryException e) {
+                       throw new CmsException("Cannot refresh header", e);
+               }
+               area.layout(true, true);
+       }
+
        protected void refreshBody() {
                // Exception
                Throwable exception = getException();
@@ -114,10 +161,10 @@ public class SimpleErgonomics extends AbstractCmsEntryPoint {
 
                try {
                        Node node = getNode();
-                       if (node == null)
-                               log.error("Context cannot be null");
-                       else
-                               uiProvider.createUi(bodyArea, node);
+//                     if (node == null)
+//                             log.error("Context cannot be null");
+//                     else
+                       uiProvider.createUi(bodyArea, node);
                } catch (RepositoryException e) {
                        throw new CmsException("Cannot refresh body", e);
                }
@@ -146,4 +193,33 @@ public class SimpleErgonomics extends AbstractCmsEntryPoint {
        public void setImageManager(CmsImageManager imageManager) {
                this.imageManager = imageManager;
        }
+
+       public CmsUiProvider getLead() {
+               return lead;
+       }
+
+       public void setLead(CmsUiProvider lead) {
+               this.lead = lead;
+       }
+
+       public CmsUiProvider getEnd() {
+               return end;
+       }
+
+       public void setEnd(CmsUiProvider end) {
+               this.end = end;
+       }
+
+       public CmsUiProvider getFooter() {
+               return footer;
+       }
+
+       public void setFooter(CmsUiProvider footer) {
+               this.footer = footer;
+       }
+
+       public CmsUiProvider getHeader() {
+               return header;
+       }
+
 }
diff --git a/org.argeo.cms.ui/src/org/argeo/cms/util/VerticalMenu.java b/org.argeo.cms.ui/src/org/argeo/cms/util/VerticalMenu.java
new file mode 100644 (file)
index 0000000..d0ea610
--- /dev/null
@@ -0,0 +1,43 @@
+package org.argeo.cms.util;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+import org.argeo.cms.ui.CmsUiProvider;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+
+public class VerticalMenu implements CmsUiProvider {
+       private List<CmsUiProvider> items = new ArrayList<CmsUiProvider>();
+
+       @Override
+       public Control createUi(Composite parent, Node context) throws RepositoryException {
+               Composite part = new Composite(parent, SWT.NONE);
+               part.setLayoutData(new GridData(SWT.LEAD, SWT.TOP, false, false));
+//             part.setData(RWT.CUSTOM_VARIANT, custom);
+               part.setLayout(CmsUtils.noSpaceGridLayout());
+               for (CmsUiProvider uiProvider : items) {
+                       Control subPart = uiProvider.createUi(part, context);
+                       subPart.setLayoutData(new GridData(SWT.LEAD, SWT.TOP, false, false));
+               }
+               return part;
+       }
+
+       public void add(CmsUiProvider uiProvider) {
+               items.add(uiProvider);
+       }
+
+       public List<CmsUiProvider> getItems() {
+               return items;
+       }
+
+       public void setItems(List<CmsUiProvider> items) {
+               this.items = items;
+       }
+
+}
index db0ae6296c5bbf9e68655721f26e416108ee183c..7560ceb30733faeed948bb189f0cd3e558eb3753 100644 (file)
@@ -118,7 +118,7 @@ public class CmsLogin implements CmsStyles, CallbackHandler {
                Locale locale = localeChoice == null ? this.defaultLocale : localeChoice.getSelectedLocale();
                credentialsBlock = new Composite(parent, SWT.NONE);
                credentialsBlock.setLayout(new GridLayout());
-               credentialsBlock.setLayoutData(CmsUtils.fillAll());
+               // credentialsBlock.setLayoutData(CmsUtils.fillAll());
 
                specificUserUi(credentialsBlock);
 
@@ -149,10 +149,12 @@ public class CmsLogin implements CmsStyles, CallbackHandler {
                // We need a composite for the traversal
                credentialsBlock = new Composite(parent, SWT.NONE);
                credentialsBlock.setLayout(new GridLayout());
-               credentialsBlock.setLayoutData(CmsUtils.fillAll());
+               // credentialsBlock.setLayoutData(CmsUtils.fillAll());
+               CmsUtils.style(credentialsBlock, CMS_LOGIN_DIALOG);
 
                Integer textWidth = 120;
-               CmsUtils.style(parent, CMS_USER_MENU);
+               if (parent instanceof Shell)
+                       CmsUtils.style(parent, CMS_USER_MENU);
                // new Label(this, SWT.NONE).setText(CmsMsg.username.lead());
                usernameT = new Text(credentialsBlock, SWT.BORDER);
                usernameT.setMessage(username.lead(locale));
@@ -216,6 +218,7 @@ public class CmsLogin implements CmsStyles, CallbackHandler {
 
        protected Composite createLocalesBlock(final Composite parent) {
                Composite c = new Composite(parent, SWT.NONE);
+               CmsUtils.style(c, CMS_USER_MENU_ITEM);
                c.setLayout(CmsUtils.noSpaceGridLayout());
                c.setLayoutData(CmsUtils.fillAll());
 
@@ -235,6 +238,7 @@ public class CmsLogin implements CmsStyles, CallbackHandler {
                for (Integer i = 0; i < locales.size(); i++) {
                        Locale locale = locales.get(i);
                        Button button = new Button(c, SWT.RADIO);
+                       CmsUtils.style(button, CMS_USER_MENU_ITEM);
                        button.setData(i);
                        button.setText(LocaleUtils.lead(locale.getDisplayName(locale), locale) + " (" + locale + ")");
                        // button.addListener(SWT.Selection, listener);