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