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
) {
31 protected Point
getInitialSize() {
32 return new Point(300, 180);
35 protected Control
createDialogArea(Composite parent
) {
36 Composite dialogarea
= (Composite
) super.createDialogArea(parent
);
37 Composite composite
= new Composite(dialogarea
, SWT
.NONE
);
38 composite
.setLayout(new GridLayout(2, false));
39 composite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false));
40 createCallbackHandlers(composite
);
45 private void createCallbackHandlers(Composite composite
) {
46 Callback
[] callbacks
= getCallbacks();
47 for (int i
= 0; i
< callbacks
.length
; i
++) {
48 Callback callback
= callbacks
[i
];
49 if (callback
instanceof TextOutputCallback
) {
50 createTextoutputHandler(composite
,
51 (TextOutputCallback
) callback
);
52 } else if (callback
instanceof NameCallback
) {
53 createNameHandler(composite
, (NameCallback
) callback
);
54 } else if (callback
instanceof PasswordCallback
) {
55 createPasswordHandler(composite
, (PasswordCallback
) callback
);
60 private void createPasswordHandler(Composite composite
,
61 final PasswordCallback callback
) {
62 Label label
= new Label(composite
, SWT
.NONE
);
63 label
.setText(callback
.getPrompt());
64 final Text passwordText
= new Text(composite
, SWT
.SINGLE
| SWT
.LEAD
65 | SWT
.PASSWORD
| SWT
.BORDER
);
67 .setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
68 passwordText
.addModifyListener(new ModifyListener() {
70 public void modifyText(ModifyEvent event
) {
71 callback
.setPassword(passwordText
.getText().toCharArray());
76 private void createNameHandler(Composite composite
,
77 final NameCallback callback
) {
78 Label label
= new Label(composite
, SWT
.NONE
);
79 label
.setText(callback
.getPrompt());
80 final Text text
= new Text(composite
, SWT
.SINGLE
| SWT
.LEAD
82 text
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
83 text
.addModifyListener(new ModifyListener() {
85 public void modifyText(ModifyEvent event
) {
86 callback
.setName(text
.getText());
91 private void createTextoutputHandler(Composite composite
,
92 TextOutputCallback callback
) {
93 // TODO: find a way to pass this information
94 // int messageType = callback.getMessageType();
95 // int dialogMessageType = IMessageProvider.NONE;
96 // switch (messageType) {
97 // case TextOutputCallback.INFORMATION:
98 // dialogMessageType = IMessageProvider.INFORMATION;
100 // case TextOutputCallback.WARNING:
101 // dialogMessageType = IMessageProvider.WARNING;
103 // case TextOutputCallback.ERROR:
104 // dialogMessageType = IMessageProvider.ERROR;
107 // setMessage(callback.getMessage(), dialogMessageType);
110 public void internalHandle() {