]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms.ui/src/org/argeo/cms/widgets/auth/DefaultLoginDialog.java
Move RCP support to Argeo SLC
[lgpl/argeo-commons.git] / org.argeo.cms.ui / src / org / argeo / cms / widgets / auth / DefaultLoginDialog.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.argeo.cms.widgets.auth;
17
18 import javax.security.auth.callback.CallbackHandler;
19
20 import org.eclipse.swt.SWT;
21 import org.eclipse.swt.graphics.Point;
22 import org.eclipse.swt.graphics.Rectangle;
23 import org.eclipse.swt.layout.GridData;
24 import org.eclipse.swt.layout.GridLayout;
25 import org.eclipse.swt.widgets.Composite;
26 import org.eclipse.swt.widgets.Control;
27 import org.eclipse.swt.widgets.Display;
28 import org.eclipse.swt.widgets.Shell;
29
30 /** Default authentication dialog, to be used as {@link CallbackHandler}. */
31 public class DefaultLoginDialog extends AbstractLoginDialog {
32 private static final long serialVersionUID = -8551827590693035734L;
33
34 public DefaultLoginDialog() {
35 this(Display.getCurrent().getActiveShell());
36 }
37
38 public DefaultLoginDialog(Shell parentShell) {
39 super(parentShell);
40 }
41
42 protected Point getInitialSize() {
43 return new Point(350, 180);
44 }
45
46 @Override
47 protected Control createContents(Composite parent) {
48 Control control = super.createContents(parent);
49 parent.pack();
50
51 // Move the dialog to the center of the top level shell.
52 Rectangle shellBounds;
53 if (Display.getCurrent().getActiveShell() != null) // RCP
54 shellBounds = Display.getCurrent().getActiveShell().getBounds();
55 else
56 shellBounds = Display.getCurrent().getBounds();// RAP
57 Point dialogSize = parent.getSize();
58 int x = shellBounds.x + (shellBounds.width - dialogSize.x) / 2;
59 int y = shellBounds.y + (shellBounds.height - dialogSize.y) / 2;
60 parent.setLocation(x, y);
61 return control;
62 }
63
64 protected Control createDialogArea(Composite parent) {
65 Composite dialogarea = (Composite) super.createDialogArea(parent);
66 CompositeCallbackHandler composite = new CompositeCallbackHandler(
67 dialogarea, SWT.NONE);
68 composite.setLayout(new GridLayout(2, false));
69 composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
70 composite.createCallbackHandlers(getCallbacks());
71 return composite;
72 }
73
74 public void internalHandle() {
75 }
76 }