]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.api.cms/src/org/argeo/api/cms/ux/CmsView.java
Merge tag 'v2.3.23' into testing
[lgpl/argeo-commons.git] / org.argeo.api.cms / src / org / argeo / api / cms / ux / CmsView.java
1 package org.argeo.api.cms.ux;
2
3 import java.net.URI;
4 import java.util.HashMap;
5 import java.util.Map;
6 import java.util.concurrent.Callable;
7 import java.util.concurrent.Executors;
8
9 import javax.security.auth.login.LoginContext;
10
11 import org.argeo.api.cms.CmsSession;
12
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";
17
18 String getUid();
19
20 UxContext getUxContext();
21
22 // NAVIGATION
23 void navigateTo(String state);
24
25 // SECURITY
26 void authChange(LoginContext loginContext);
27
28 void logout();
29
30 // void registerCallbackHandler(CallbackHandler callbackHandler);
31
32 // SERVICES
33 void exception(Throwable e);
34
35 <V, M> CmsImageManager<V, M> getImageManager();
36
37 boolean isAnonymous();
38
39 /**
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
43 * server and a port.
44 */
45 URI toBackendUri(String url);
46
47 /**
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.
50 */
51 default void sendEvent(String topic, Map<String, Object> properties) {
52
53 }
54
55 /**
56 * Convenience methods for when {@link #sendEvent(String, Map)} only requires
57 * one single parameter.
58 */
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);
63 }
64
65 default void applyStyles(Object widget) {
66
67 }
68
69 /**
70 * Make sure that this action is executed with the proper subject and in a
71 * proper thread.
72 */
73 <T> T doAs(Callable<T> action);
74
75 default void runAs(Runnable runnable) {
76 doAs(Executors.callable(runnable));
77 }
78
79 default void stateChanged(String state, String title) {
80 }
81
82 default CmsSession getCmsSession() {
83 throw new UnsupportedOperationException();
84 }
85
86 default Object getData(String key) {
87 throw new UnsupportedOperationException();
88 }
89
90 @SuppressWarnings("unchecked")
91 default <T> T getUiContext(Class<T> clss) {
92 return (T) getData(clss.getName());
93 }
94
95 default <T> void setUiContext(Class<T> clss, T instance) {
96 setData(clss.getName(), instance);
97 }
98
99 default void setData(String key, Object value) {
100 throw new UnsupportedOperationException();
101 }
102
103 }