1 package org
.argeo
.security
.ui
.dialogs
;
3 import javax
.security
.auth
.callback
.Callback
;
4 import javax
.security
.auth
.callback
.CallbackHandler
;
5 import javax
.security
.auth
.callback
.NameCallback
;
6 import javax
.security
.auth
.callback
.PasswordCallback
;
7 import javax
.security
.auth
.callback
.TextOutputCallback
;
9 import org
.eclipse
.swt
.SWT
;
10 import org
.eclipse
.swt
.events
.ModifyEvent
;
11 import org
.eclipse
.swt
.events
.ModifyListener
;
12 import org
.eclipse
.swt
.graphics
.Point
;
13 import org
.eclipse
.swt
.graphics
.Rectangle
;
14 import org
.eclipse
.swt
.layout
.GridData
;
15 import org
.eclipse
.swt
.layout
.GridLayout
;
16 import org
.eclipse
.swt
.widgets
.Composite
;
17 import org
.eclipse
.swt
.widgets
.Control
;
18 import org
.eclipse
.swt
.widgets
.Display
;
19 import org
.eclipse
.swt
.widgets
.Label
;
20 import org
.eclipse
.swt
.widgets
.Shell
;
21 import org
.eclipse
.swt
.widgets
.Text
;
23 /** Default authentication dialog, to be used as {@link CallbackHandler}. */
24 public class DefaultLoginDialog
extends AbstractLoginDialog
{
26 public DefaultLoginDialog() {
27 this(Display
.getCurrent().getActiveShell());
30 protected DefaultLoginDialog(Shell parentShell
) {
34 protected Point
getInitialSize() {
35 return new Point(300, 180);
39 protected Control
createContents(Composite parent
) {
40 Control control
= super.createContents(parent
);
42 // Move the dialog to the center of the top level shell.
43 Rectangle shellBounds
= Display
.getCurrent().getBounds();
44 Point dialogSize
= parent
.getSize();
45 int x
= shellBounds
.x
+ (shellBounds
.width
- dialogSize
.x
) / 2;
46 int y
= shellBounds
.y
+ (shellBounds
.height
- dialogSize
.y
) / 2;
47 parent
.setLocation(x
, y
);
51 protected Control
createDialogArea(Composite parent
) {
52 Composite dialogarea
= (Composite
) super.createDialogArea(parent
);
53 Composite composite
= new Composite(dialogarea
, SWT
.NONE
);
54 composite
.setLayout(new GridLayout(2, false));
55 composite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false));
56 createCallbackHandlers(composite
);
61 private void createCallbackHandlers(Composite composite
) {
62 Callback
[] callbacks
= getCallbacks();
63 for (int i
= 0; i
< callbacks
.length
; i
++) {
64 Callback callback
= callbacks
[i
];
65 if (callback
instanceof TextOutputCallback
) {
66 createLabelTextoutputHandler(composite
,
67 (TextOutputCallback
) callback
);
68 } else if (callback
instanceof NameCallback
) {
69 createNameHandler(composite
, (NameCallback
) callback
);
70 } else if (callback
instanceof PasswordCallback
) {
71 createPasswordHandler(composite
, (PasswordCallback
) callback
);
76 private void createPasswordHandler(Composite composite
,
77 final PasswordCallback callback
) {
78 Label label
= new Label(composite
, SWT
.NONE
);
79 label
.setText(callback
.getPrompt());
80 final Text passwordText
= new Text(composite
, SWT
.SINGLE
| SWT
.LEAD
81 | SWT
.PASSWORD
| SWT
.BORDER
);
83 .setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
84 passwordText
.addModifyListener(new ModifyListener() {
86 public void modifyText(ModifyEvent event
) {
87 // FIXME use getTextChars() in Eclipse 3.7
88 callback
.setPassword(passwordText
.getText().toCharArray());
93 private void createNameHandler(Composite composite
,
94 final NameCallback callback
) {
95 Label label
= new Label(composite
, SWT
.NONE
);
96 label
.setText(callback
.getPrompt());
97 final Text text
= new Text(composite
, SWT
.SINGLE
| SWT
.LEAD
99 text
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
100 text
.addModifyListener(new ModifyListener() {
102 public void modifyText(ModifyEvent event
) {
103 callback
.setName(text
.getText());
108 private void createLabelTextoutputHandler(Composite composite
,
109 final TextOutputCallback callback
) {
110 Label label
= new Label(composite
, SWT
.NONE
);
111 label
.setText(callback
.getMessage());
112 GridData data
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true);
113 data
.horizontalSpan
= 2;
114 label
.setLayoutData(data
);
115 // TODO: find a way to pass this information
116 // int messageType = callback.getMessageType();
117 // int dialogMessageType = IMessageProvider.NONE;
118 // switch (messageType) {
119 // case TextOutputCallback.INFORMATION:
120 // dialogMessageType = IMessageProvider.INFORMATION;
122 // case TextOutputCallback.WARNING:
123 // dialogMessageType = IMessageProvider.WARNING;
125 // case TextOutputCallback.ERROR:
126 // dialogMessageType = IMessageProvider.ERROR;
129 // setMessage(callback.getMessage(), dialogMessageType);
132 public void internalHandle() {