Working multi RCP platform
[lgpl/argeo-commons.git] / swt / rcp / org.argeo.cms.swt.rcp / src / org / argeo / cms / ui / rcp / CmsRcpApp.java
index a88ff3824fa07c2ee2d02d093104ce0ad93060fd..7af1456b7dad68905d30986101ef50781a8033bd 100644 (file)
@@ -2,6 +2,8 @@ package org.argeo.cms.ui.rcp;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.security.PrivilegedAction;
 import java.util.Map;
 import java.util.UUID;
@@ -15,10 +17,12 @@ import org.argeo.api.cms.CmsAuth;
 import org.argeo.api.cms.CmsEventBus;
 import org.argeo.api.cms.CmsLog;
 import org.argeo.api.cms.CmsSession;
+import org.argeo.api.cms.ux.CmsImageManager;
 import org.argeo.api.cms.ux.CmsTheme;
 import org.argeo.api.cms.ux.CmsView;
 import org.argeo.cms.swt.AbstractSwtCmsView;
 import org.argeo.cms.swt.CmsSwtUtils;
+import org.argeo.cms.swt.acr.AcrSwtImageManager;
 import org.eclipse.e4.ui.css.core.engine.CSSEngine;
 import org.eclipse.e4.ui.css.core.engine.CSSErrorHandler;
 import org.eclipse.e4.ui.css.swt.engine.CSSSWTEngineImpl;
@@ -36,12 +40,17 @@ public class CmsRcpApp extends AbstractSwtCmsView implements CmsView {
 
        private CSSEngine cssEngine;
 
+       private String httpServerBase;
+
        public CmsRcpApp(String uiName) {
                super(uiName);
                uid = UUID.randomUUID().toString();
        }
 
+       @SuppressWarnings("rawtypes")
        public void initRcpApp() {
+               imageManager = (CmsImageManager) new AcrSwtImageManager();
+
                display = Display.getCurrent();
                shell = new Shell(display);
                shell.setText("Argeo CMS");
@@ -72,20 +81,24 @@ public class CmsRcpApp extends AbstractSwtCmsView implements CmsView {
                        // Styling
                        CmsTheme theme = CmsSwtUtils.getCmsTheme(parent);
                        if (theme != null) {
-                               cssEngine = new CSSSWTEngineImpl(display);
-                               for (String path : theme.getSwtCssPaths()) {
-                                       try (InputStream in = theme.loadPath(path)) {
-                                               cssEngine.parseStyleSheet(in);
-                                       } catch (IOException e) {
-                                               throw new IllegalStateException("Cannot load stylesheet " + path, e);
+                               try {
+                                       cssEngine = new CSSSWTEngineImpl(display);
+                                       for (String path : theme.getSwtCssPaths()) {
+                                               try (InputStream in = theme.loadPath(path)) {
+                                                       cssEngine.parseStyleSheet(in);
+                                               } catch (IOException e) {
+                                                       throw new IllegalStateException("Cannot load stylesheet " + path, e);
+                                               }
                                        }
+                                       cssEngine.setErrorHandler(new CSSErrorHandler() {
+                                               public void error(Exception e) {
+                                                       log.error("SWT styling error: ", e);
+                                               }
+                                       });
+                                       applyStyles(shell);
+                               } catch (Throwable e) {// could be a class not found error
+                                       log.error("Cannot initialise RCP theming", e);
                                }
-                               cssEngine.setErrorHandler(new CSSErrorHandler() {
-                                       public void error(Exception e) {
-                                               log.error("SWT styling error: ", e);
-                                       }
-                               });
-                               applyStyles(shell);
                        }
                        shell.layout(true, true);
 
@@ -153,6 +166,24 @@ public class CmsRcpApp extends AbstractSwtCmsView implements CmsView {
                return cmsApp;
        }
 
+       @Override
+       public URI toBackendUri(String url) {
+               try {
+                       URI u = new URI(url);
+                       if (u.getHost() == null) {
+                               // TODO make it more robust
+                               u = new URI(httpServerBase + url);
+                       }
+                       return u;
+               } catch (URISyntaxException e) {
+                       throw new IllegalArgumentException("Cannot convert " + url, e);
+               }
+       }
+
+       public void setHttpServerBase(String httpServerBase) {
+               this.httpServerBase = httpServerBase;
+       }
+
        /*
         * DEPENDENCY INJECTION
         */