X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=rcp%2Forg.argeo.cms.ui.rcp%2Fsrc%2Forg%2Fargeo%2Fcms%2Fui%2Frcp%2FCmsRcpApp.java;h=ed019d706b1114f6f545319ffbf7e43dcc0649dc;hb=c2366f32052deada7d96f635e86f745f438f094e;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..ed019d706 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,7 +13,6 @@ 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; @@ -21,12 +20,10 @@ 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.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; @@ -42,13 +39,9 @@ public class CmsRcpApp implements CmsView { 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 +54,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; + loginContext = new LoginContext(CmsAuth.SINGLE_USER.getLoginContextName()); + loginContext.login(); + } catch (LoginException e) { + throw new IllegalStateException("Could not log in.", e); } - } - - class CmsUiThread extends Thread { - - public CmsUiThread() { - super("CMS UI"); - } - - @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 +157,7 @@ public class CmsRcpApp implements CmsView { @Override public CmsSession getCmsSession() { - CmsSession cmsSession = CmsOsgiUtils.getCmsSession(bundleContext, getSubject()); + CmsSession cmsSession = cmsApp.getCmsContext().getCmsSession(getSubject()); return cmsSession; } @@ -274,10 +212,14 @@ public class CmsRcpApp implements CmsView { /* * 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; }