1 package org
.argeo
.cms
.ui
;
3 import java
.security
.PrivilegedAction
;
4 import java
.util
.HashMap
;
7 import javax
.security
.auth
.login
.LoginContext
;
9 import org
.argeo
.cms
.auth
.CmsSession
;
10 import org
.eclipse
.swt
.widgets
.Control
;
11 import org
.eclipse
.swt
.widgets
.Shell
;
13 /** Provides interaction with the CMS system. */
14 public interface CmsView
{
15 final static String CMS_VIEW_UID_PROPERTY
= "argeo.cms.view.uid";
16 // String KEY = "org.argeo.cms.ui.view";
20 UxContext
getUxContext();
23 void navigateTo(String state
);
26 void authChange(LoginContext loginContext
);
30 // void registerCallbackHandler(CallbackHandler callbackHandler);
33 void exception(Throwable e
);
35 CmsImageManager
getImageManager();
37 boolean isAnonymous();
40 * Send an event to this topic. Does nothing by default., but if implemented it
41 * MUST set the {@link #CMS_VIEW_UID_PROPERTY} in the properties.
43 default void sendEvent(String topic
, Map
<String
, Object
> properties
) {
48 * Convenience methods for when {@link #sendEvent(String, Map)} only requires
49 * one single parameter.
51 default void sendEvent(String topic
, String param
, Object value
) {
52 Map
<String
, Object
> properties
= new HashMap
<>();
53 properties
.put(param
, value
);
54 sendEvent(topic
, properties
);
57 default void applyStyles(Object widget
) {
61 default <T
> T
doAs(PrivilegedAction
<T
> action
) {
62 throw new UnsupportedOperationException();
65 default Void
runAs(Runnable runnable
) {
66 return doAs(new PrivilegedAction
<Void
>() {
77 default void stateChanged(String state
, String title
) {
80 default CmsSession
getCmsSession() {
81 throw new UnsupportedOperationException();
84 default Object
getData(String key
) {
85 throw new UnsupportedOperationException();
88 @SuppressWarnings("unchecked")
89 default <T
> T
getUiContext(Class
<T
> clss
) {
90 return (T
) getData(clss
.getName());
93 default <T
> void setUiContext(Class
<T
> clss
, T instance
) {
94 setData(clss
.getName(), instance
);
97 default void setData(String key
, Object value
) {
98 throw new UnsupportedOperationException();
101 static CmsView
getCmsView(Control parent
) {
103 Shell topShell
= parent
.getShell();
104 while (topShell
.getParent() != null)
105 topShell
= (Shell
) topShell
.getParent();
106 return (CmsView
) topShell
.getData(CmsView
.class.getName());
109 static void registerCmsView(Shell shell
, CmsView view
) {
111 Shell topShell
= shell
;
112 while (topShell
.getParent() != null)
113 topShell
= (Shell
) topShell
.getParent();
114 // check if already set
115 if (topShell
.getData(CmsView
.class.getName()) != null) {
116 CmsView registeredView
= (CmsView
) topShell
.getData(CmsView
.class.getName());
117 throw new IllegalArgumentException("Cms view " + registeredView
+ " already registered in this shell");
119 shell
.setData(CmsView
.class.getName(), view
);