]> git.argeo.org Git - lgpl/argeo-commons.git/blob - CmsView.java
15b6a5dc7aac338a7180f748fa404c31f4f28bb0
[lgpl/argeo-commons.git] / CmsView.java
1 package org.argeo.api.cms.ux;
2
3 import java.util.HashMap;
4 import java.util.Map;
5 import java.util.concurrent.Callable;
6 import java.util.concurrent.Executors;
7
8 import javax.security.auth.login.LoginContext;
9
10 import org.argeo.api.cms.CmsSession;
11
12 /** Provides interaction with the CMS system. */
13 public interface CmsView {
14 final static String CMS_VIEW_UID_PROPERTY = "argeo.cms.view.uid";
15 // String KEY = "org.argeo.cms.ui.view";
16
17 String getUid();
18
19 UxContext getUxContext();
20
21 // NAVIGATION
22 void navigateTo(String state);
23
24 // SECURITY
25 void authChange(LoginContext loginContext);
26
27 void logout();
28
29 // void registerCallbackHandler(CallbackHandler callbackHandler);
30
31 // SERVICES
32 void exception(Throwable e);
33
34 CmsImageManager<?, ?> getImageManager();
35
36 boolean isAnonymous();
37
38 /**
39 * Send an event to this topic. Does nothing by default., but if implemented it
40 * MUST set the {@link #CMS_VIEW_UID_PROPERTY} in the properties.
41 */
42 default void sendEvent(String topic, Map<String, Object> properties) {
43
44 }
45
46 /**
47 * Convenience methods for when {@link #sendEvent(String, Map)} only requires
48 * one single parameter.
49 */
50 default void sendEvent(String topic, String param, Object value) {
51 Map<String, Object> properties = new HashMap<>();
52 properties.put(param, value);
53 sendEvent(topic, properties);
54 }
55
56 default void applyStyles(Object widget) {
57
58 }
59
60 /**
61 * Make sure that this action is executed with the proper subject and in a
62 * proper thread.
63 */
64 <T> T doAs(Callable<T> action);
65
66 default void runAs(Runnable runnable) {
67 doAs(Executors.callable(runnable));
68 }
69
70 default void stateChanged(String state, String title) {
71 }
72
73 default CmsSession getCmsSession() {
74 throw new UnsupportedOperationException();
75 }
76
77 default Object getData(String key) {
78 throw new UnsupportedOperationException();
79 }
80
81 @SuppressWarnings("unchecked")
82 default <T> T getUiContext(Class<T> clss) {
83 return (T) getData(clss.getName());
84 }
85
86 default <T> void setUiContext(Class<T> clss, T instance) {
87 setData(clss.getName(), instance);
88 }
89
90 default void setData(String key, Object value) {
91 throw new UnsupportedOperationException();
92 }
93
94 }