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);
37 protected Control
createContents(Composite parent
) {
38 Control control
= super.createContents(parent
);
43 protected Control
createDialogArea(Composite parent
) {
44 Composite dialogarea
= (Composite
) super.createDialogArea(parent
);
45 Composite composite
= new Composite(dialogarea
, SWT
.NONE
);
46 composite
.setLayout(new GridLayout(2, false));
47 composite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false));
48 createCallbackHandlers(composite
);
53 private void createCallbackHandlers(Composite composite
) {
54 Callback
[] callbacks
= getCallbacks();
55 for (int i
= 0; i
< callbacks
.length
; i
++) {
56 Callback callback
= callbacks
[i
];
57 if (callback
instanceof TextOutputCallback
) {
58 createLabelTextoutputHandler(composite
,
59 (TextOutputCallback
) callback
);
60 } else if (callback
instanceof NameCallback
) {
61 createNameHandler(composite
, (NameCallback
) callback
);
62 } else if (callback
instanceof PasswordCallback
) {
63 createPasswordHandler(composite
, (PasswordCallback
) callback
);
68 private void createPasswordHandler(Composite composite
,
69 final PasswordCallback callback
) {
70 Label label
= new Label(composite
, SWT
.NONE
);
71 label
.setText(callback
.getPrompt());
72 final Text passwordText
= new Text(composite
, SWT
.SINGLE
| SWT
.LEAD
73 | SWT
.PASSWORD
| SWT
.BORDER
);
75 .setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
76 passwordText
.addModifyListener(new ModifyListener() {
78 public void modifyText(ModifyEvent event
) {
79 // FIXME use getTextChars() in Eclipse 3.7
80 callback
.setPassword(passwordText
.getText().toCharArray());
85 private void createNameHandler(Composite composite
,
86 final NameCallback callback
) {
87 Label label
= new Label(composite
, SWT
.NONE
);
88 label
.setText(callback
.getPrompt());
89 final Text text
= new Text(composite
, SWT
.SINGLE
| SWT
.LEAD
91 text
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
92 text
.addModifyListener(new ModifyListener() {
94 public void modifyText(ModifyEvent event
) {
95 callback
.setName(text
.getText());
100 private void createLabelTextoutputHandler(Composite composite
,
101 final TextOutputCallback callback
) {
102 Label label
= new Label(composite
, SWT
.NONE
);
103 label
.setText(callback
.getMessage());
104 GridData data
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true);
105 data
.horizontalSpan
= 2;
106 label
.setLayoutData(data
);
107 // TODO: find a way to pass this information
108 // int messageType = callback.getMessageType();
109 // int dialogMessageType = IMessageProvider.NONE;
110 // switch (messageType) {
111 // case TextOutputCallback.INFORMATION:
112 // dialogMessageType = IMessageProvider.INFORMATION;
114 // case TextOutputCallback.WARNING:
115 // dialogMessageType = IMessageProvider.WARNING;
117 // case TextOutputCallback.ERROR:
118 // dialogMessageType = IMessageProvider.ERROR;
121 // setMessage(callback.getMessage(), dialogMessageType);
124 public void internalHandle() {
127 // hack to simulate modal
129 // http://dev.eclipse.org/mhonarc/newsLists/news.eclipse.platform.jface/msg00181.html
130 // protected void setShellStyle(int newShellStyle) {
131 // // turn off APPLICATION_MODAL
132 // int newstyle = newShellStyle & ~SWT.APPLICATION_MODAL;
133 // // turn on MODELESS
134 // newstyle |= SWT.MODELESS;
135 // super.setShellStyle(newstyle);
138 // public int open() {
140 // int retVal = super.open();
141 // // this will let the caller wait till OK, Cancel is
142 // // pressed, but will let the other GUI responsive
147 // protected void pumpMessages() {
148 // Shell sh = getShell();
149 // Display disp = sh.getDisplay();
150 // while (!sh.isDisposed()) {
151 // if (!disp.readAndDispatch())