Merge Fix: Default callback handler not working in RAP
authorMathieu Baudier <mbaudier@argeo.org>
Thu, 30 May 2013 17:02:30 +0000 (17:02 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Thu, 30 May 2013 17:02:30 +0000 (17:02 +0000)
https://www.argeo.org/bugzilla/show_bug.cgi?id=161

git-svn-id: https://svn.argeo.org/commons/trunk@6318 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/SecurityUiPlugin.java
security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/dialogs/DefaultLoginDialog.java

index b7c4ef45f59caa5a9af9ed744e8c6cde0755cda0..b6bab756b653a0d8beaa18fd0d4c3791a12a69c0 100644 (file)
@@ -44,33 +44,19 @@ public class SecurityUiPlugin extends AbstractUIPlugin {
 
        private static SecurityUiPlugin plugin;
 
+       public static InheritableThreadLocal<Display> display = new InheritableThreadLocal<Display>() {
+
+               @Override
+               protected Display initialValue() {
+                       return Display.getCurrent();
+               }
+       };
+
        public void start(BundleContext context) throws Exception {
                super.start(context);
                plugin = this;
 
-               final Display display = Display.getCurrent();
-               defaultCallbackHandler = new CallbackHandler() {
-                       public void handle(final Callback[] callbacks) throws IOException,
-                                       UnsupportedCallbackException {
-
-                               if (display != null) // RCP
-                                       display.syncExec(new Runnable() {
-                                               public void run() {
-                                                       DefaultLoginDialog dialog = new DefaultLoginDialog();
-                                                       try {
-                                                               dialog.handle(callbacks);
-                                                       } catch (IOException e) {
-                                                               throw new ArgeoException("Cannot open dialog",
-                                                                               e);
-                                                       }
-                                               }
-                                       });
-                               else {// RAP
-                                       DefaultLoginDialog dialog = new DefaultLoginDialog();
-                                       dialog.handle(callbacks);
-                               }
-                       }
-               };
+               defaultCallbackHandler = new DefaultCallbackHandler();
                defaultCallbackHandlerReg = context.registerService(
                                CallbackHandler.class.getName(), defaultCallbackHandler, null);
        }
@@ -93,4 +79,28 @@ public class SecurityUiPlugin extends AbstractUIPlugin {
        public static ImageDescriptor getImageDescriptor(String path) {
                return imageDescriptorFromPlugin(PLUGIN_ID, path);
        }
+
+       protected class DefaultCallbackHandler implements CallbackHandler {
+               public void handle(final Callback[] callbacks) throws IOException,
+                               UnsupportedCallbackException {
+
+                       // if (display != null) // RCP
+                       display.get().syncExec(new Runnable() {
+                               public void run() {
+                                       DefaultLoginDialog dialog = new DefaultLoginDialog(display
+                                                       .get().getActiveShell());
+                                       try {
+                                               dialog.handle(callbacks);
+                                       } catch (IOException e) {
+                                               throw new ArgeoException("Cannot open dialog", e);
+                                       }
+                               }
+                       });
+                       // else {// RAP
+                       // DefaultLoginDialog dialog = new DefaultLoginDialog();
+                       // dialog.handle(callbacks);
+                       // }
+               }
+
+       }
 }
index 3a67efccabfce4491d66545410f04ba34301ddd4..57ba01b5bab8863799a9a1c656ff40f919b3f465 100644 (file)
@@ -21,6 +21,7 @@ import javax.security.auth.callback.NameCallback;
 import javax.security.auth.callback.PasswordCallback;
 import javax.security.auth.callback.TextOutputCallback;
 
+import org.argeo.security.ui.SecurityUiPlugin;
 import org.argeo.util.LocaleCallback;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.ModifyEvent;
@@ -41,12 +42,11 @@ import org.eclipse.swt.widgets.Text;
 
 /** Default authentication dialog, to be used as {@link CallbackHandler}. */
 public class DefaultLoginDialog extends AbstractLoginDialog {
-
        public DefaultLoginDialog() {
-               this(Display.getCurrent().getActiveShell());
+               this(SecurityUiPlugin.display.get().getActiveShell());
        }
 
-       protected DefaultLoginDialog(Shell parentShell) {
+       public DefaultLoginDialog(Shell parentShell) {
                super(parentShell);
        }