]> git.argeo.org Git - lgpl/argeo-commons.git/blob - CmsView.java
b403a2088d33fbfcb703c49c1bdf11762eca4b6d
[lgpl/argeo-commons.git] / CmsView.java
1 package org.argeo.cms.ui;
2
3 import java.util.HashMap;
4 import java.util.Map;
5
6 import javax.security.auth.login.LoginContext;
7
8 import org.eclipse.swt.widgets.Composite;
9 import org.eclipse.swt.widgets.Shell;
10
11 /** Provides interaction with the CMS system. */
12 public interface CmsView {
13 final static String CMS_VIEW_UID_PROPERTY = "argeo.cms.view.uid";
14 // String KEY = "org.argeo.cms.ui.view";
15
16 String getUid();
17
18 UxContext getUxContext();
19
20 // NAVIGATION
21 void navigateTo(String state);
22
23 // SECURITY
24 void authChange(LoginContext loginContext);
25
26 void logout();
27
28 // void registerCallbackHandler(CallbackHandler callbackHandler);
29
30 // SERVICES
31 void exception(Throwable e);
32
33 CmsImageManager getImageManager();
34
35 boolean isAnonymous();
36
37 /**
38 * Send an event to this topic. Does noothing by default., but if implemented it
39 * MUST set the {@link #CMS_VIEW_UID_PROPERTY} in the properties.
40 */
41 default void sendEvent(String topic, Map<String, Object> properties) {
42
43 }
44
45 /**
46 * Convenience methods for when {@link #sendEvent(String, Map)} only requires
47 * one single parameter.
48 */
49 default void sendEvent(String topic, String param, Object value) {
50 Map<String, Object> properties = new HashMap<>();
51 properties.put(param, value);
52 sendEvent(topic, properties);
53 }
54
55 default void applyStyles(Object widget) {
56
57 }
58
59 static CmsView getCmsView(Composite parent) {
60 // find parent shell
61 Shell topShell = parent.getShell();
62 while (topShell.getParent() != null)
63 topShell = (Shell) topShell.getParent();
64 return (CmsView) topShell.getData(CmsView.class.getName());
65 }
66
67 static void registerCmsView(Shell shell, CmsView view) {
68 // find parent shell
69 Shell topShell = shell;
70 while (topShell.getParent() != null)
71 topShell = (Shell) topShell.getParent();
72 // check if already set
73 if (topShell.getData(CmsView.class.getName()) != null) {
74 CmsView registeredView = (CmsView) topShell.getData(CmsView.class.getName());
75 throw new IllegalArgumentException("Cms view " + registeredView + " already registered in this shell");
76 }
77 shell.setData(CmsView.class.getName(), view);
78 }
79
80 }