1 package org
.argeo
.cms
.swt
;
3 import java
.security
.PrivilegedAction
;
4 import java
.util
.HashMap
;
6 import java
.util
.concurrent
.CompletableFuture
;
7 import java
.util
.concurrent
.ExecutionException
;
9 import javax
.security
.auth
.Subject
;
10 import javax
.security
.auth
.login
.LoginContext
;
12 import org
.argeo
.api
.cms
.CmsEventBus
;
13 import org
.argeo
.api
.cms
.ux
.CmsImageManager
;
14 import org
.argeo
.api
.cms
.ux
.CmsUi
;
15 import org
.argeo
.api
.cms
.ux
.CmsView
;
16 import org
.argeo
.api
.cms
.ux
.UxContext
;
17 import org
.argeo
.cms
.auth
.CurrentUser
;
18 import org
.eclipse
.swt
.widgets
.Display
;
20 public abstract class AbstractSwtCmsView
implements CmsView
{
21 protected final String uiName
;
23 protected LoginContext loginContext
;
24 protected String state
;
25 protected Throwable exception
;
26 protected UxContext uxContext
;
27 protected CmsImageManager imageManager
;
29 protected Display display
;
34 public AbstractSwtCmsView(String uiName
) {
38 public abstract CmsEventBus
getCmsEventBus();
41 public void sendEvent(String topic
, Map
<String
, Object
> properties
) {
42 if (properties
== null)
43 properties
= new HashMap
<>();
44 if (properties
.containsKey(CMS_VIEW_UID_PROPERTY
) && !properties
.get(CMS_VIEW_UID_PROPERTY
).equals(uid
))
45 throw new IllegalArgumentException("Property " + CMS_VIEW_UID_PROPERTY
+ " is set to another CMS view uid ("
46 + properties
.get(CMS_VIEW_UID_PROPERTY
) + ") then " + uid
);
47 properties
.put(CMS_VIEW_UID_PROPERTY
, uid
);
48 getCmsEventBus().sendEvent(topic
, properties
);
51 public <T
> T
doAs(PrivilegedAction
<T
> action
) {
53 CompletableFuture
<T
> result
= new CompletableFuture
<>();
54 Runnable toDo
= () -> {
55 T res
= Subject
.doAs(getSubject(), action
);
58 if (Thread
.currentThread() == display
.getThread())
61 display
.syncExec(toDo
);
63 } catch (InterruptedException
| ExecutionException e
) {
64 throw new IllegalStateException("Cannot execute action ins CMS view " + uid
, e
);
69 public UxContext
getUxContext() {
74 public String
getUid() {
79 public CmsImageManager
<?
, ?
> getImageManager() {
84 public boolean isAnonymous() {
85 return CurrentUser
.isAnonymous(getSubject());
88 protected Subject
getSubject() {
89 return loginContext
.getSubject();
93 public Object
getData(String key
) {
95 return ui
.getData(key
);
97 throw new IllegalStateException("UI is not initialized");
102 public void setData(String key
, Object value
) {
104 ui
.setData(key
, value
);
106 throw new IllegalStateException("UI is not initialized");