]> git.argeo.org Git - lgpl/argeo-commons.git/blob - auth/DefaultLoginDialog.java
Prepare next development cycle
[lgpl/argeo-commons.git] / auth / DefaultLoginDialog.java
1 package org.argeo.cms.ui.widgets.auth;
2
3 import javax.security.auth.callback.CallbackHandler;
4
5 import org.eclipse.swt.SWT;
6 import org.eclipse.swt.graphics.Point;
7 import org.eclipse.swt.graphics.Rectangle;
8 import org.eclipse.swt.layout.GridData;
9 import org.eclipse.swt.layout.GridLayout;
10 import org.eclipse.swt.widgets.Composite;
11 import org.eclipse.swt.widgets.Control;
12 import org.eclipse.swt.widgets.Display;
13 import org.eclipse.swt.widgets.Shell;
14
15 /** Default authentication dialog, to be used as {@link CallbackHandler}. */
16 public class DefaultLoginDialog extends AbstractLoginDialog {
17 private static final long serialVersionUID = -8551827590693035734L;
18
19 public DefaultLoginDialog() {
20 this(Display.getCurrent().getActiveShell());
21 }
22
23 public DefaultLoginDialog(Shell parentShell) {
24 super(parentShell);
25 }
26
27 protected Point getInitialSize() {
28 return new Point(350, 180);
29 }
30
31 @Override
32 protected Control createContents(Composite parent) {
33 Control control = super.createContents(parent);
34 parent.pack();
35
36 // Move the dialog to the center of the top level shell.
37 Rectangle shellBounds;
38 if (Display.getCurrent().getActiveShell() != null) // RCP
39 shellBounds = Display.getCurrent().getActiveShell().getBounds();
40 else
41 shellBounds = Display.getCurrent().getBounds();// RAP
42 Point dialogSize = parent.getSize();
43 int x = shellBounds.x + (shellBounds.width - dialogSize.x) / 2;
44 int y = shellBounds.y + (shellBounds.height - dialogSize.y) / 2;
45 parent.setLocation(x, y);
46 return control;
47 }
48
49 protected Control createDialogArea(Composite parent) {
50 Composite dialogarea = (Composite) super.createDialogArea(parent);
51 CompositeCallbackHandler composite = new CompositeCallbackHandler(
52 dialogarea, SWT.NONE);
53 composite.setLayout(new GridLayout(2, false));
54 composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
55 composite.createCallbackHandlers(getCallbacks());
56 return composite;
57 }
58
59 public void internalHandle() {
60 }
61 }