]> git.argeo.org Git - lgpl/argeo-commons.git/blob - src/org/argeo/cms/ui/CmsView.java
Prepare next development cycle
[lgpl/argeo-commons.git] / src / org / argeo / cms / ui / 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 static CmsView getCmsView(Composite parent) {
56 // find parent shell
57 Shell topShell = parent.getShell();
58 while (topShell.getParent() != null)
59 topShell = (Shell) topShell.getParent();
60 return (CmsView) topShell.getData(CmsView.class.getName());
61 }
62
63 static void registerCmsView(Shell shell, CmsView view) {
64 // find parent shell
65 Shell topShell = shell;
66 while (topShell.getParent() != null)
67 topShell = (Shell) topShell.getParent();
68 // check if already set
69 if (topShell.getData(CmsView.class.getName()) != null) {
70 CmsView registeredView = (CmsView) topShell.getData(CmsView.class.getName());
71 throw new IllegalArgumentException("Cms view " + registeredView + " already registered in this shell");
72 }
73 shell.setData(CmsView.class.getName(), view);
74 }
75
76 }