1 package org
.argeo
.cms
.ui
.rcp
;
3 import java
.nio
.file
.Path
;
5 import org
.argeo
.api
.cms
.CmsApp
;
6 import org
.argeo
.util
.OS
;
7 import org
.eclipse
.swt
.widgets
.Display
;
8 import org
.osgi
.service
.event
.EventAdmin
;
9 import org
.eclipse
.swt
.events
.DisposeListener
;
11 /** Creates the SWT {@link Display} in a dedicated thread. */
12 public class CmsRcpDisplayFactory
{
13 /** File name in a run directory */
14 private final static String ARGEO_RCP_URL
= "argeo.rcp.url";
16 /** There is only one display in RCP mode */
17 private static Display display
;
19 private CmsUiThread uiThread
;
21 private boolean shutdown
= false;
24 uiThread
= new CmsUiThread();
26 while (display
== null)
29 } catch (InterruptedException e
) {
34 public void destroy() {
39 } catch (InterruptedException e
) {
46 class CmsUiThread
extends Thread
{
48 public CmsUiThread() {
54 display
= Display
.getDefault();
55 display
.setRuntimeExceptionHandler((e
) -> e
.printStackTrace());
56 display
.setErrorHandler((e
) -> e
.printStackTrace());
58 // for (String contextName : cmsApps.keySet()) {
59 // openCmsApp(contextName);
63 if (!display
.readAndDispatch())
71 public static Display
getDisplay() {
75 public static void openCmsApp(EventAdmin eventAdmin
, CmsApp cmsApp
, String uiName
,
76 DisposeListener disposeListener
) {
77 CmsRcpDisplayFactory
.getDisplay().syncExec(() -> {
78 CmsRcpApp cmsRcpApp
= new CmsRcpApp(uiName
);
79 cmsRcpApp
.setEventAdmin(eventAdmin
);
80 cmsRcpApp
.setCmsApp(cmsApp
, null);
81 cmsRcpApp
.initRcpApp();
82 if (disposeListener
!= null)
83 cmsRcpApp
.getShell().addDisposeListener(disposeListener
);
87 public static Path
getUrlRunFile() {
88 return OS
.getRunDir().resolve(CmsRcpDisplayFactory
.ARGEO_RCP_URL
);