]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/dialogs/AbstractLoginDialog.java
1 package org
.argeo
.security
.ui
.dialogs
;
3 import java
.io
.IOException
;
5 import javax
.security
.auth
.callback
.Callback
;
6 import javax
.security
.auth
.callback
.CallbackHandler
;
8 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
9 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
10 import org
.eclipse
.jface
.dialogs
.IDialogConstants
;
11 import org
.eclipse
.jface
.dialogs
.TitleAreaDialog
;
12 import org
.eclipse
.jface
.operation
.IRunnableWithProgress
;
13 import org
.eclipse
.jface
.operation
.ModalContext
;
14 import org
.eclipse
.swt
.events
.SelectionEvent
;
15 import org
.eclipse
.swt
.events
.SelectionListener
;
16 import org
.eclipse
.swt
.widgets
.Button
;
17 import org
.eclipse
.swt
.widgets
.Display
;
18 import org
.eclipse
.swt
.widgets
.Shell
;
20 public abstract class AbstractLoginDialog
extends TitleAreaDialog
implements
23 boolean processCallbacks
= false;
24 boolean isCancelled
= false;
25 Callback
[] callbackArray
;
27 protected final Callback
[] getCallbacks() {
28 return this.callbackArray
;
31 public abstract void internalHandle();
33 public boolean isCancelled() {
37 protected AbstractLoginDialog(Shell parentShell
) {
45 * javax.security.auth.callback.CallbackHandler#handle(javax.security.auth
46 * .callback.Callback[])
48 public void handle(final Callback
[] callbacks
) throws IOException
{
49 this.callbackArray
= callbacks
;
50 final Display display
= Display
.getDefault();
51 display
.syncExec(new Runnable() {
55 setBlockOnOpen(false);
57 final Button okButton
= getButton(IDialogConstants
.OK_ID
);
58 okButton
.setText("Login");
59 okButton
.addSelectionListener(new SelectionListener() {
61 public void widgetSelected(final SelectionEvent event
) {
62 processCallbacks
= true;
65 public void widgetDefaultSelected(final SelectionEvent event
) {
69 final Button cancel
= getButton(IDialogConstants
.CANCEL_ID
);
70 cancel
.addSelectionListener(new SelectionListener() {
72 public void widgetSelected(final SelectionEvent event
) {
74 processCallbacks
= true;
77 public void widgetDefaultSelected(final SelectionEvent event
) {
84 ModalContext
.setAllowReadAndDispatch(true); // Works for now.
85 ModalContext
.run(new IRunnableWithProgress() {
87 public void run(final IProgressMonitor monitor
) {
88 // Wait here until OK or cancel is pressed, then let it rip.
91 // is responsible for closing the dialog (in the
94 while (!processCallbacks
) {
97 } catch (final Exception e
) {
101 processCallbacks
= false;
102 // Call the adapter to handle the callbacks
106 }, true, new NullProgressMonitor(), Display
.getDefault());
107 } catch (final Exception e
) {
108 final IOException ioe
= new IOException();
114 protected void configureShell(Shell shell
) {
115 super.configureShell(shell
);
116 shell
.setText("Login");