1 package org
.argeo
.security
.ui
.dialogs
;
3 import javax
.security
.auth
.callback
.Callback
;
4 import javax
.security
.auth
.callback
.NameCallback
;
5 import javax
.security
.auth
.callback
.PasswordCallback
;
6 import javax
.security
.auth
.callback
.TextOutputCallback
;
8 import org
.eclipse
.swt
.SWT
;
9 import org
.eclipse
.swt
.events
.ModifyEvent
;
10 import org
.eclipse
.swt
.events
.ModifyListener
;
11 import org
.eclipse
.swt
.graphics
.Point
;
12 import org
.eclipse
.swt
.layout
.GridData
;
13 import org
.eclipse
.swt
.layout
.GridLayout
;
14 import org
.eclipse
.swt
.widgets
.Composite
;
15 import org
.eclipse
.swt
.widgets
.Control
;
16 import org
.eclipse
.swt
.widgets
.Display
;
17 import org
.eclipse
.swt
.widgets
.Label
;
18 import org
.eclipse
.swt
.widgets
.Shell
;
19 import org
.eclipse
.swt
.widgets
.Text
;
21 public class DefaultLoginDialog
extends AbstractLoginDialog
{
23 public DefaultLoginDialog() {
24 this(Display
.getCurrent().getActiveShell());
27 protected DefaultLoginDialog(Shell parentShell
) {
29 // setBlockOnOpen(false);
32 protected Point
getInitialSize() {
33 return new Point(300, 180);
36 protected Control
createDialogArea(Composite parent
) {
37 Composite dialogarea
= (Composite
) super.createDialogArea(parent
);
38 Composite composite
= new Composite(dialogarea
, SWT
.NONE
);
39 composite
.setLayout(new GridLayout(2, false));
40 composite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false));
41 createCallbackHandlers(composite
);
46 private void createCallbackHandlers(Composite composite
) {
47 Callback
[] callbacks
= getCallbacks();
48 for (int i
= 0; i
< callbacks
.length
; i
++) {
49 Callback callback
= callbacks
[i
];
50 if (callback
instanceof TextOutputCallback
) {
51 createTextoutputHandler(composite
,
52 (TextOutputCallback
) callback
);
53 } else if (callback
instanceof NameCallback
) {
54 createNameHandler(composite
, (NameCallback
) callback
);
55 } else if (callback
instanceof PasswordCallback
) {
56 createPasswordHandler(composite
, (PasswordCallback
) callback
);
61 private void createPasswordHandler(Composite composite
,
62 final PasswordCallback callback
) {
63 Label label
= new Label(composite
, SWT
.NONE
);
64 label
.setText(callback
.getPrompt());
65 final Text passwordText
= new Text(composite
, SWT
.SINGLE
| SWT
.LEAD
66 | SWT
.PASSWORD
| SWT
.BORDER
);
68 .setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
69 passwordText
.addModifyListener(new ModifyListener() {
71 public void modifyText(ModifyEvent event
) {
72 callback
.setPassword(passwordText
.getText().toCharArray());
77 private void createNameHandler(Composite composite
,
78 final NameCallback callback
) {
79 Label label
= new Label(composite
, SWT
.NONE
);
80 label
.setText(callback
.getPrompt());
81 final Text text
= new Text(composite
, SWT
.SINGLE
| SWT
.LEAD
83 text
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
84 text
.addModifyListener(new ModifyListener() {
86 public void modifyText(ModifyEvent event
) {
87 callback
.setName(text
.getText());
92 private void createTextoutputHandler(Composite composite
,
93 TextOutputCallback callback
) {
94 // TODO: find a way to pass this information
95 // int messageType = callback.getMessageType();
96 // int dialogMessageType = IMessageProvider.NONE;
97 // switch (messageType) {
98 // case TextOutputCallback.INFORMATION:
99 // dialogMessageType = IMessageProvider.INFORMATION;
101 // case TextOutputCallback.WARNING:
102 // dialogMessageType = IMessageProvider.WARNING;
104 // case TextOutputCallback.ERROR:
105 // dialogMessageType = IMessageProvider.ERROR;
108 // setMessage(callback.getMessage(), dialogMessageType);
111 public void internalHandle() {
114 // hack to simulate modal
116 // http://dev.eclipse.org/mhonarc/newsLists/news.eclipse.platform.jface/msg00181.html
117 // protected void setShellStyle(int newShellStyle) {
118 // // turn off APPLICATION_MODAL
119 // int newstyle = newShellStyle & ~SWT.APPLICATION_MODAL;
120 // // turn on MODELESS
121 // newstyle |= SWT.MODELESS;
122 // super.setShellStyle(newstyle);
125 // public int open() {
127 // int retVal = super.open();
128 // // this will let the caller wait till OK, Cancel is
129 // // pressed, but will let the other GUI responsive
134 // protected void pumpMessages() {
135 // Shell sh = getShell();
136 // Display disp = sh.getDisplay();
137 // while (!sh.isDisposed()) {
138 // if (!disp.readAndDispatch())