2 * Copyright (C) 2007-2012 Argeo GmbH
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org
.argeo
.security
.ui
.auth
;
18 import javax
.security
.auth
.callback
.CallbackHandler
;
20 import org
.argeo
.security
.ui
.SecurityUiPlugin
;
21 import org
.eclipse
.swt
.SWT
;
22 import org
.eclipse
.swt
.graphics
.Point
;
23 import org
.eclipse
.swt
.graphics
.Rectangle
;
24 import org
.eclipse
.swt
.layout
.GridData
;
25 import org
.eclipse
.swt
.layout
.GridLayout
;
26 import org
.eclipse
.swt
.widgets
.Composite
;
27 import org
.eclipse
.swt
.widgets
.Control
;
28 import org
.eclipse
.swt
.widgets
.Display
;
29 import org
.eclipse
.swt
.widgets
.Shell
;
31 /** Default authentication dialog, to be used as {@link CallbackHandler}. */
32 public class DefaultLoginDialog
extends AbstractLoginDialog
{
33 private static final long serialVersionUID
= -8551827590693035734L;
35 public DefaultLoginDialog() {
36 this(SecurityUiPlugin
.display
.get().getActiveShell());
39 public DefaultLoginDialog(Shell parentShell
) {
43 protected Point
getInitialSize() {
44 return new Point(350, 180);
48 protected Control
createContents(Composite parent
) {
49 Control control
= super.createContents(parent
);
52 // Move the dialog to the center of the top level shell.
53 Rectangle shellBounds
;
54 if (Display
.getCurrent().getActiveShell() != null) // RCP
55 shellBounds
= Display
.getCurrent().getActiveShell().getBounds();
57 shellBounds
= Display
.getCurrent().getBounds();// RAP
58 Point dialogSize
= parent
.getSize();
59 int x
= shellBounds
.x
+ (shellBounds
.width
- dialogSize
.x
) / 2;
60 int y
= shellBounds
.y
+ (shellBounds
.height
- dialogSize
.y
) / 2;
61 parent
.setLocation(x
, y
);
65 protected Control
createDialogArea(Composite parent
) {
66 Composite dialogarea
= (Composite
) super.createDialogArea(parent
);
67 CompositeCallbackHandler composite
= new CompositeCallbackHandler(
68 dialogarea
, SWT
.NONE
);
69 composite
.setLayout(new GridLayout(2, false));
70 composite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false));
71 composite
.createCallbackHandlers(getCallbacks());
75 public void internalHandle() {