Improve RCP launch
[lgpl/argeo-commons.git] / org.argeo.api.cms / src / org / argeo / api / cms / ux / CmsView.java
index 45629fba5bdd387947f0236b211a366783a3953c..121e4bdcbf601a654fc608aeda89ec895f4b4e3b 100644 (file)
@@ -1,14 +1,16 @@
 package org.argeo.api.cms.ux;
 
-import java.security.PrivilegedAction;
+import java.net.URI;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.concurrent.Executors;
 
 import javax.security.auth.login.LoginContext;
 
 import org.argeo.api.cms.CmsSession;
 
-/** Provides interaction with the CMS system. */
+/** Provides UX interactions with the CMS system. */
 public interface CmsView {
        final static String CMS_VIEW_UID_PROPERTY = "argeo.cms.view.uid";
        // String KEY = "org.argeo.cms.ui.view";
@@ -30,10 +32,18 @@ public interface CmsView {
        // SERVICES
        void exception(Throwable e);
 
-       CmsImageManager<?, ?> getImageManager();
+       <V, M> CmsImageManager<V, M> getImageManager();
 
        boolean isAnonymous();
 
+       /**
+        * Translates to an URL that can be reached by a client, depending on its type.
+        * Typically, if a web interface asks for /path/on/the/web/server it will be
+        * returned without modifications; but a thin client will probably need to add a
+        * server and a port.
+        */
+       URI toBackendUri(String url);
+
        /**
         * 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.
@@ -56,20 +66,14 @@ public interface CmsView {
 
        }
 
-       default <T> T doAs(PrivilegedAction<T> action) {
-               throw new UnsupportedOperationException();
-       }
-
-       default Void runAs(Runnable runnable) {
-               return doAs(new PrivilegedAction<Void>() {
+       /**
+        * Make sure that this action is executed with the proper subject and in a
+        * proper thread.
+        */
+       <T> T doAs(Callable<T> action);
 
-                       @Override
-                       public Void run() {
-                               if (runnable != null)
-                                       runnable.run();
-                               return null;
-                       }
-               });
+       default void runAs(Runnable runnable) {
+               doAs(Executors.callable(runnable));
        }
 
        default void stateChanged(String state, String title) {