1 package org
.argeo
.api
.cms
.ux
;
4 import java
.util
.HashMap
;
6 import java
.util
.concurrent
.Callable
;
7 import java
.util
.concurrent
.Executors
;
9 import javax
.security
.auth
.login
.LoginContext
;
11 import org
.argeo
.api
.cms
.CmsSession
;
13 /** Provides UX interactions 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 <V
, M
> CmsImageManager
<V
, M
> getImageManager();
37 boolean isAnonymous();
40 * Translates to an URL that can be reached by a client, depending on its type.
41 * Typically, if a web interface asks for /path/on/the/web/server it will be
42 * returned without modifications; but a thin client will probably need to add a
45 URI
toBackendUri(String url
);
48 * Send an event to this topic. Does nothing by default., but if implemented it
49 * MUST set the {@link #CMS_VIEW_UID_PROPERTY} in the properties.
51 default void sendEvent(String topic
, Map
<String
, Object
> properties
) {
56 * Convenience methods for when {@link #sendEvent(String, Map)} only requires
57 * one single parameter.
59 default void sendEvent(String topic
, String param
, Object value
) {
60 Map
<String
, Object
> properties
= new HashMap
<>();
61 properties
.put(param
, value
);
62 sendEvent(topic
, properties
);
65 default void applyStyles(Object widget
) {
70 * Make sure that this action is executed with the proper subject and in a
73 <T
> T
doAs(Callable
<T
> action
);
75 default void runAs(Runnable runnable
) {
76 doAs(Executors
.callable(runnable
));
79 default void stateChanged(String state
, String title
) {
82 default CmsSession
getCmsSession() {
83 throw new UnsupportedOperationException();
86 default Object
getData(String key
) {
87 throw new UnsupportedOperationException();
90 @SuppressWarnings("unchecked")
91 default <T
> T
getUiContext(Class
<T
> clss
) {
92 return (T
) getData(clss
.getName());
95 default <T
> void setUiContext(Class
<T
> clss
, T instance
) {
96 setData(clss
.getName(), instance
);
99 default void setData(String key
, Object value
) {
100 throw new UnsupportedOperationException();