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
.jface
.dialogs
.IMessageProvider
;
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
.layout
.GridData
;
14 import org
.eclipse
.swt
.layout
.GridLayout
;
15 import org
.eclipse
.swt
.widgets
.Composite
;
16 import org
.eclipse
.swt
.widgets
.Control
;
17 import org
.eclipse
.swt
.widgets
.Display
;
18 import org
.eclipse
.swt
.widgets
.Label
;
19 import org
.eclipse
.swt
.widgets
.Shell
;
20 import org
.eclipse
.swt
.widgets
.Text
;
22 public class DefaultLoginDialog
extends AbstractLoginDialog
{
24 public DefaultLoginDialog() {
25 this(Display
.getCurrent().getActiveShell());
28 protected DefaultLoginDialog(Shell parentShell
) {
32 protected Point
getInitialSize() {
33 return new Point(300, 150);
36 protected Control
createDialogArea(Composite parent
) {
37 Composite dialogarea
= (Composite
) super.createDialogArea(parent
);
38 // dialogarea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
40 Composite composite
= new Composite(dialogarea
, SWT
.NONE
);
41 composite
.setLayout(new GridLayout(2, false));
42 composite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false));
43 createCallbackHandlers(composite
);
48 private void createCallbackHandlers(Composite composite
) {
49 Callback
[] callbacks
= getCallbacks();
50 for (int i
= 0; i
< callbacks
.length
; i
++) {
51 Callback callback
= callbacks
[i
];
52 if (callback
instanceof TextOutputCallback
) {
53 createTextoutputHandler(composite
,
54 (TextOutputCallback
) callback
);
55 } else if (callback
instanceof NameCallback
) {
56 createNameHandler(composite
, (NameCallback
) callback
);
57 } else if (callback
instanceof PasswordCallback
) {
58 createPasswordHandler(composite
, (PasswordCallback
) callback
);
63 private void createPasswordHandler(Composite composite
,
64 final PasswordCallback callback
) {
65 Label label
= new Label(composite
, SWT
.NONE
);
66 label
.setText(callback
.getPrompt());
67 final Text passwordText
= new Text(composite
, SWT
.SINGLE
| SWT
.LEAD
68 | SWT
.PASSWORD
| SWT
.BORDER
);
70 .setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
71 passwordText
.addModifyListener(new ModifyListener() {
73 public void modifyText(ModifyEvent event
) {
74 callback
.setPassword(passwordText
.getText().toCharArray());
79 private void createNameHandler(Composite composite
,
80 final NameCallback callback
) {
81 Label label
= new Label(composite
, SWT
.NONE
);
82 label
.setText(callback
.getPrompt());
83 final Text text
= new Text(composite
, SWT
.SINGLE
| SWT
.LEAD
85 text
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
86 text
.addModifyListener(new ModifyListener() {
88 public void modifyText(ModifyEvent event
) {
89 callback
.setName(text
.getText());
94 private void createTextoutputHandler(Composite composite
,
95 TextOutputCallback callback
) {
96 int messageType
= callback
.getMessageType();
97 int dialogMessageType
= IMessageProvider
.NONE
;
98 switch (messageType
) {
99 case TextOutputCallback
.INFORMATION
:
100 dialogMessageType
= IMessageProvider
.INFORMATION
;
102 case TextOutputCallback
.WARNING
:
103 dialogMessageType
= IMessageProvider
.WARNING
;
105 case TextOutputCallback
.ERROR
:
106 dialogMessageType
= IMessageProvider
.ERROR
;
109 //setMessage(callback.getMessage(), dialogMessageType);
112 public void internalHandle() {