Extend UI context.
[lgpl/argeo-commons.git] / org.argeo.cms.ui / src / org / argeo / cms / ui / CmsView.java
index 311d10fbe9d22f2c1db2db8e9f55d14a9db7a850..f8ab3a6821cf09860bdb052e6b118c377d3053ed 100644 (file)
@@ -1,10 +1,12 @@
 package org.argeo.cms.ui;
 
+import java.security.PrivilegedAction;
 import java.util.HashMap;
 import java.util.Map;
 
 import javax.security.auth.login.LoginContext;
 
+import org.argeo.cms.auth.CmsSession;
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Shell;
 
@@ -35,7 +37,7 @@ public interface CmsView {
        boolean isAnonymous();
 
        /**
-        * Send an event to this topic. Does noothing by default., but if implemented it
+        * Send an event to this topic. Does nothing by default., but if implemented it
         * MUST set the {@link #CMS_VIEW_UID_PROPERTY} in the properties.
         */
        default void sendEvent(String topic, Map<String, Object> properties) {
@@ -51,9 +53,49 @@ public interface CmsView {
                properties.put(param, value);
                sendEvent(topic, properties);
        }
-       
+
        default void applyStyles(Object widget) {
-               
+
+       }
+
+       default <T> T doAs(PrivilegedAction<T> action) {
+               throw new UnsupportedOperationException();
+       }
+
+       default Void runAs(Runnable runnable) {
+               return doAs(new PrivilegedAction<Void>() {
+
+                       @Override
+                       public Void run() {
+                               if (runnable != null)
+                                       runnable.run();
+                               return null;
+                       }
+               });
+       }
+
+       default void stateChanged(String state, String title) {
+       }
+
+       default CmsSession getCmsSession() {
+               throw new UnsupportedOperationException();
+       }
+
+       default Object getData(String key) {
+               throw new UnsupportedOperationException();
+       }
+
+       @SuppressWarnings("unchecked")
+       default <T> T getUiContext(Class<T> clss) {
+               return (T) getData(clss.getName());
+       }
+
+       default <T> void setUiContext(Class<T> clss, T instance) {
+               setData(clss.getName(), instance);
+       }
+
+       default void setData(String key, Object value) {
+               throw new UnsupportedOperationException();
        }
 
        static CmsView getCmsView(Control parent) {