X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=rcp%2Forg.argeo.cms.ui.rcp%2Fsrc%2Forg%2Fargeo%2Fcms%2Fui%2Frcp%2FCmsRcpApp.java;h=e25a9f71149b66d0aaf2168e4f0fe31e936e8e92;hb=5cbd7544d8243c7f0f0f5c1a78daac979aee20e4;hp=fb56773b86bb8bac3744d09e71766045fea377e5;hpb=abf105d0153d3f54bbdb3bb3c70689949cb739be;p=lgpl%2Fargeo-commons.git diff --git a/rcp/org.argeo.cms.ui.rcp/src/org/argeo/cms/ui/rcp/CmsRcpApp.java b/rcp/org.argeo.cms.ui.rcp/src/org/argeo/cms/ui/rcp/CmsRcpApp.java index fb56773b8..e25a9f711 100644 --- a/rcp/org.argeo.cms.ui.rcp/src/org/argeo/cms/ui/rcp/CmsRcpApp.java +++ b/rcp/org.argeo.cms.ui.rcp/src/org/argeo/cms/ui/rcp/CmsRcpApp.java @@ -13,25 +13,20 @@ import javax.security.auth.login.LoginException; import org.argeo.api.cms.CmsApp; import org.argeo.api.cms.CmsAuth; -import org.argeo.api.cms.CmsContext; -import org.argeo.api.cms.CmsImageManager; import org.argeo.api.cms.CmsLog; import org.argeo.api.cms.CmsSession; -import org.argeo.api.cms.CmsTheme; -import org.argeo.api.cms.CmsUi; -import org.argeo.api.cms.CmsView; -import org.argeo.api.cms.UxContext; -import org.argeo.cms.osgi.CmsOsgiUtils; +import org.argeo.api.cms.ux.CmsImageManager; +import org.argeo.api.cms.ux.CmsTheme; +import org.argeo.api.cms.ux.CmsUi; +import org.argeo.api.cms.ux.CmsView; +import org.argeo.api.cms.ux.UxContext; import org.argeo.cms.swt.CmsSwtUtils; 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; -import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; -import org.osgi.framework.BundleContext; -import org.osgi.framework.FrameworkUtil; import org.osgi.service.event.Event; import org.osgi.service.event.EventAdmin; @@ -40,15 +35,12 @@ import org.osgi.service.event.EventAdmin; public class CmsRcpApp implements CmsView { private final static CmsLog log = CmsLog.getLog(CmsRcpApp.class); - private BundleContext bundleContext = FrameworkUtil.getBundle(CmsRcpApp.class).getBundleContext(); + // private BundleContext bundleContext = + // FrameworkUtil.getBundle(CmsRcpApp.class).getBundleContext(); - private Display display; private Shell shell; private CmsApp cmsApp; - private CmsUiThread uiThread; - private CmsContext cmsContext; - // CMS View private String uid; private LoginContext loginContext; @@ -61,123 +53,68 @@ public class CmsRcpApp implements CmsView { // TODO make it configurable private String uiName = "desktop"; - public CmsRcpApp() { + public CmsRcpApp(String uiName) { uid = UUID.randomUUID().toString(); + this.uiName = uiName; } - public void init(Map properties) { - try { - Thread.sleep(5000); - } catch (InterruptedException e) { - // silent - } - uiThread = new CmsUiThread(); - uiThread.start(); - - } + public void initRcpApp() { + Display display = Display.getCurrent(); + shell = new Shell(display); + shell.setText("Argeo CMS"); + Composite parent = shell; + parent.setLayout(CmsSwtUtils.noSpaceGridLayout()); + CmsSwtUtils.registerCmsView(shell, CmsRcpApp.this); - public void destroy(Map properties) { - if (!shell.isDisposed()) - shell.dispose(); try { - uiThread.join(); - } catch (InterruptedException e) { - // silent - } finally { - uiThread = null; - } - } - - class CmsUiThread extends Thread { - - public CmsUiThread() { - super("CMS UI"); + loginContext = new LoginContext(CmsAuth.SINGLE_USER.getLoginContextName()); + loginContext.login(); + } catch (LoginException e) { + throw new IllegalStateException("Could not log in.", e); } - - @Override - public void run() { - display = Display.getDefault(); - shell = new Shell(display); - shell.setText("Argeo CMS"); - Composite parent = shell; - parent.setLayout(new GridLayout()); - CmsSwtUtils.registerCmsView(shell, CmsRcpApp.this); - -// Subject subject = new Subject(); -// CmsLoginShell loginShell = new CmsLoginShell(CmsRcpApp.this); -// loginShell.setSubject(subject); - try { - // try pre-auth -// loginContext = new LoginContext(NodeConstants.LOGIN_CONTEXT_USER, subject, loginShell); - loginContext = new LoginContext(CmsAuth.LOGIN_CONTEXT_SINGLE_USER); - loginContext.login(); - } catch (LoginException e) { - throw new IllegalStateException("Could not log in.", e); -// loginShell.createUi(); -// loginShell.open(); -// -// while (!loginShell.getShell().isDisposed()) { -// if (!display.readAndDispatch()) -// display.sleep(); -// } - } - if (log.isDebugEnabled()) - log.debug("Logged in to desktop: " + loginContext.getSubject()); - - Subject.doAs(loginContext.getSubject(), (PrivilegedAction) () -> { - - // TODO factorise with web app - parent.setData(CmsApp.UI_NAME_PROPERTY, uiName); - ui = cmsApp.initUi(parent); - if (ui instanceof Composite) - ((Composite) ui).setLayoutData(CmsSwtUtils.fillAll()); - // ui.setLayoutData(CmsUiUtils.fillAll()); - // we need ui to be set before refresh so that CmsView can store UI context data - // in it. - cmsApp.refreshUi(ui, null); - - // 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); - } + if (log.isDebugEnabled()) + log.debug("Logged in to desktop: " + loginContext.getSubject()); + + Subject.doAs(loginContext.getSubject(), (PrivilegedAction) () -> { + + // TODO factorise with web app + parent.setData(CmsApp.UI_NAME_PROPERTY, uiName); + ui = cmsApp.initUi(parent); + if (ui instanceof Composite) + ((Composite) ui).setLayoutData(CmsSwtUtils.fillAll()); + // we need ui to be set before refresh so that CmsView can store UI context data + // in it. + cmsApp.refreshUi(ui, null); + + // 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); } - cssEngine.setErrorHandler(new CSSErrorHandler() { - public void error(Exception e) { - log.error("SWT styling error: ", e); - } - }); - applyStyles(shell); } - shell.layout(true, true); - - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - display.dispose(); - return null; - }); - } + cssEngine.setErrorHandler(new CSSErrorHandler() { + public void error(Exception e) { + log.error("SWT styling error: ", e); + } + }); + applyStyles(shell); + } + shell.layout(true, true); + shell.open(); + return null; + }); } - - /* * CMS VIEW */ - public void setCmsContext(CmsContext cmsContext) { - this.cmsContext = cmsContext; - } - @Override public String getUid() { return uid; @@ -219,7 +156,7 @@ public class CmsRcpApp implements CmsView { @Override public CmsSession getCmsSession() { - CmsSession cmsSession = CmsOsgiUtils.getCmsSession(bundleContext, getSubject()); + CmsSession cmsSession = cmsApp.getCmsContext().getCmsSession(getSubject()); return cmsSession; } @@ -271,13 +208,21 @@ public class CmsRcpApp implements CmsView { return loginContext.getSubject(); } + public Shell getShell() { + return shell; + } + /* * DEPENDENCY INJECTION */ - public void setCmsApp(CmsApp cmsApp) { + public void setCmsApp(CmsApp cmsApp, Map properties) { this.cmsApp = cmsApp; } + public void unsetCmsApp(CmsApp cmsApp, Map properties) { + this.cmsApp = null; + } + public void setEventAdmin(EventAdmin eventAdmin) { this.eventAdmin = eventAdmin; }