Introduce CMS App concept.
authorMathieu Baudier <mbaudier@argeo.org>
Sat, 3 Oct 2020 15:41:12 +0000 (17:41 +0200)
committerMathieu Baudier <mbaudier@argeo.org>
Sat, 3 Oct 2020 15:41:12 +0000 (17:41 +0200)
org.argeo.cms.ui/src/org/argeo/cms/ui/CmsApp.java [new file with mode: 0644]
org.argeo.cms.ui/src/org/argeo/cms/ui/util/CmsStyle.java [new file with mode: 0644]
org.argeo.cms.ui/src/org/argeo/cms/ui/util/CmsUiUtils.java
org.argeo.cms.ui/src/org/argeo/cms/web/CmsWebApp.java [new file with mode: 0644]
org.argeo.cms.ui/src/org/argeo/cms/web/MinimalWebApp.java

diff --git a/org.argeo.cms.ui/src/org/argeo/cms/ui/CmsApp.java b/org.argeo.cms.ui/src/org/argeo/cms/ui/CmsApp.java
new file mode 100644 (file)
index 0000000..b8d3825
--- /dev/null
@@ -0,0 +1,12 @@
+package org.argeo.cms.ui;
+
+import java.util.Set;
+
+import org.eclipse.swt.widgets.Composite;
+
+/** An extensible user interface base on the CMS backend. */
+public interface CmsApp {
+       Set<String> getUiNames();
+
+       void initUi(String uiName, Composite parent);
+}
diff --git a/org.argeo.cms.ui/src/org/argeo/cms/ui/util/CmsStyle.java b/org.argeo.cms.ui/src/org/argeo/cms/ui/util/CmsStyle.java
new file mode 100644 (file)
index 0000000..79d5bb6
--- /dev/null
@@ -0,0 +1,12 @@
+package org.argeo.cms.ui.util;
+
+/** Can be applied to {@link Enum}s in order to generated (CSS) class names. */
+public interface CmsStyle {
+       default String toStyleClass() {
+               return getClassPrefix() + "-" + ((Enum<?>) this).name();
+       }
+
+       default String getClassPrefix() {
+               return "cms";
+       }
+}
index 1671c90cc3400616aaeb09eb36dbba46b71773c2..3669db3fdb35ad9061f7ef993a5cf3415dae2fb5 100644 (file)
@@ -115,7 +115,7 @@ public class CmsUiUtils implements CmsConstants {
        }
 
        public static GridData fillHeight() {
-               return grabWidth(SWT.FILL, SWT.FILL);
+               return grabHeight(SWT.FILL, SWT.FILL);
        }
 
        public static GridData grabHeight(int horizontalAlignment, int verticalAlignment) {
@@ -132,6 +132,12 @@ public class CmsUiUtils implements CmsConstants {
                return widget;
        }
 
+       /** Style widget */
+       public static <T extends Widget> T style(T widget, CmsStyle style) {
+               widget.setData(CmsConstants.STYLE, style.toStyleClass());
+               return widget;
+       }
+
        /** Enable markups on widget */
        public static <T extends Widget> T markup(T widget) {
                widget.setData(CmsConstants.MARKUP, true);
diff --git a/org.argeo.cms.ui/src/org/argeo/cms/web/CmsWebApp.java b/org.argeo.cms.ui/src/org/argeo/cms/web/CmsWebApp.java
new file mode 100644 (file)
index 0000000..cae02fd
--- /dev/null
@@ -0,0 +1,38 @@
+package org.argeo.cms.web;
+
+import java.util.Map;
+
+import org.argeo.cms.ui.CmsApp;
+import org.eclipse.rap.rwt.application.AbstractEntryPoint;
+import org.eclipse.rap.rwt.application.Application;
+import org.eclipse.swt.widgets.Composite;
+
+public class CmsWebApp extends MinimalWebApp {
+       private CmsApp cmsApp;
+
+       @Override
+       protected void addEntryPoints(Application application, Map<String, String> properties) {
+               for (String uiName : cmsApp.getUiNames()) {
+                       application.addEntryPoint("/" + uiName, () -> {
+                               return new AbstractEntryPoint() {
+                                       private static final long serialVersionUID = -9153259126766694485L;
+
+                                       @Override
+                                       protected void createContents(Composite parent) {
+                                               cmsApp.initUi(uiName, parent);
+
+                                       }
+                               };
+                       }, properties);
+               }
+       }
+
+       public CmsApp getCmsApp() {
+               return cmsApp;
+       }
+
+       public void setCmsApp(CmsApp cmsApp) {
+               this.cmsApp = cmsApp;
+       }
+
+}
index 31c93af22c92dc0dbe1e2b03ffe49747de0e175d..fe8b20c92097286b31e9dc63986ac50502f7dbbb 100644 (file)
@@ -1,7 +1,6 @@
 package org.argeo.cms.web;
 
 import static org.argeo.cms.ui.util.CmsTheme.CMS_THEME_BUNDLE_PROPERTY;
-import static org.argeo.cms.ui.util.CmsTheme.DEFAULT_CMS_THEME_BUNDLE;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -22,8 +21,6 @@ public class MinimalWebApp implements ApplicationConfiguration {
                if (properties.containsKey(CMS_THEME_BUNDLE_PROPERTY)) {
                        String cmsThemeBundle = properties.get(CMS_THEME_BUNDLE_PROPERTY).toString();
                        theme = new CmsTheme(bundleContext, cmsThemeBundle);
-               } else {
-                       theme = new CmsTheme(bundleContext, DEFAULT_CMS_THEME_BUNDLE);
                }
        }
 
@@ -38,11 +35,16 @@ public class MinimalWebApp implements ApplicationConfiguration {
 
        @Override
        public void configure(Application application) {
-               theme.apply(application);
+               if (theme != null)
+                       theme.apply(application);
 
                Map<String, String> properties = new HashMap<>();
-               properties.put(WebClient.THEME_ID, RWT.DEFAULT_THEME_ID);
-               properties.put(WebClient.HEAD_HTML, theme.getAdditionalHeaders());
+               if (theme != null) {
+                       properties.put(WebClient.THEME_ID, theme.getThemeId());
+                       properties.put(WebClient.HEAD_HTML, theme.getAdditionalHeaders());
+               } else {
+                       properties.put(WebClient.THEME_ID, RWT.DEFAULT_THEME_ID);
+               }
                addEntryPoints(application, properties);
 
        }