Introduce CMS App concept.
[lgpl/argeo-commons.git] / org.argeo.cms.ui / src / org / argeo / cms / web / MinimalWebApp.java
index b4af7595d231604e8f07e3696faebb92ace33eb0..fe8b20c92097286b31e9dc63986ac50502f7dbbb 100644 (file)
@@ -1,18 +1,15 @@
 package org.argeo.cms.web;
 
+import static org.argeo.cms.ui.util.CmsTheme.CMS_THEME_BUNDLE_PROPERTY;
+
 import java.util.HashMap;
 import java.util.Map;
 
 import org.argeo.cms.ui.util.CmsTheme;
 import org.eclipse.rap.rwt.RWT;
-import org.eclipse.rap.rwt.application.AbstractEntryPoint;
 import org.eclipse.rap.rwt.application.Application;
 import org.eclipse.rap.rwt.application.ApplicationConfiguration;
 import org.eclipse.rap.rwt.client.WebClient;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Label;
 import org.osgi.framework.BundleContext;
 
 /** Lightweight web app using only RWT and not the whole Eclipse platform. */
@@ -20,34 +17,35 @@ public class MinimalWebApp implements ApplicationConfiguration {
 
        private CmsTheme theme;
 
-       public void init(BundleContext bundleContext) {
-               theme = new CmsTheme(bundleContext);
+       public void init(BundleContext bundleContext, Map<String, Object> properties) {
+               if (properties.containsKey(CMS_THEME_BUNDLE_PROPERTY)) {
+                       String cmsThemeBundle = properties.get(CMS_THEME_BUNDLE_PROPERTY).toString();
+                       theme = new CmsTheme(bundleContext, cmsThemeBundle);
+               }
        }
 
        public void destroy() {
 
        }
 
-       @Override
-       public void configure(Application application) {
-               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());
-               application.addEntryPoint("/test", TextEntryPoint.class, properties);
+       /** To be overridden. Does nothing by default. */
+       protected void addEntryPoints(Application application, Map<String, String> properties) {
 
        }
 
-       static class TextEntryPoint extends AbstractEntryPoint {
-               private static final long serialVersionUID = 2245808564950897823L;
+       @Override
+       public void configure(Application application) {
+               if (theme != null)
+                       theme.apply(application);
 
-               @Override
-               protected void createContents(Composite parent) {
-                       parent.setLayout(new GridLayout());
-                       new Label(parent, SWT.NONE).setText("Hello World!");
+               Map<String, String> properties = new HashMap<>();
+               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);
 
        }
-
 }