X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=security%2Fplugins%2Forg.argeo.security.ui%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fsecurity%2Fui%2Fdialogs%2FDefaultLoginDialog.java;h=c07e8a9dfc0060a7963d0e4d9e72bfec1b760a1d;hb=3baeb167c9a92d1f915904bb956632c0aff65b2b;hp=8c8554c6b77a0ef8ff2700acc4590f190617a4ba;hpb=78469faf92044c7ad7b3a829ae2b5e4f943748b7;p=lgpl%2Fargeo-commons.git diff --git a/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/dialogs/DefaultLoginDialog.java b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/dialogs/DefaultLoginDialog.java index 8c8554c6b..c07e8a9df 100644 --- a/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/dialogs/DefaultLoginDialog.java +++ b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/dialogs/DefaultLoginDialog.java @@ -1,6 +1,22 @@ +/* + * Copyright (C) 2007-2012 Mathieu Baudier + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.argeo.security.ui.dialogs; import javax.security.auth.callback.Callback; +import javax.security.auth.callback.CallbackHandler; import javax.security.auth.callback.NameCallback; import javax.security.auth.callback.PasswordCallback; import javax.security.auth.callback.TextOutputCallback; @@ -9,6 +25,7 @@ import org.eclipse.swt.SWT; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; @@ -18,6 +35,7 @@ import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; +/** Default authentication dialog, to be used as {@link CallbackHandler}. */ public class DefaultLoginDialog extends AbstractLoginDialog { public DefaultLoginDialog() { @@ -26,7 +44,6 @@ public class DefaultLoginDialog extends AbstractLoginDialog { protected DefaultLoginDialog(Shell parentShell) { super(parentShell); - // setBlockOnOpen(false); } protected Point getInitialSize() { @@ -37,6 +54,12 @@ public class DefaultLoginDialog extends AbstractLoginDialog { protected Control createContents(Composite parent) { Control control = super.createContents(parent); parent.pack(); + // Move the dialog to the center of the top level shell. + Rectangle shellBounds = Display.getCurrent().getBounds(); + Point dialogSize = parent.getSize(); + int x = shellBounds.x + (shellBounds.width - dialogSize.x) / 2; + int y = shellBounds.y + (shellBounds.height - dialogSize.y) / 2; + parent.setLocation(x, y); return control; } @@ -88,6 +111,11 @@ public class DefaultLoginDialog extends AbstractLoginDialog { label.setText(callback.getPrompt()); final Text text = new Text(composite, SWT.SINGLE | SWT.LEAD | SWT.BORDER); + if (callback.getDefaultName() != null) { + // set default value, if provided + text.setText(callback.getDefaultName()); + callback.setName(callback.getDefaultName()); + } text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); text.addModifyListener(new ModifyListener() { @@ -123,35 +151,4 @@ public class DefaultLoginDialog extends AbstractLoginDialog { public void internalHandle() { } - - // hack to simulate modal - // see - // http://dev.eclipse.org/mhonarc/newsLists/news.eclipse.platform.jface/msg00181.html - // protected void setShellStyle(int newShellStyle) { - // // turn off APPLICATION_MODAL - // int newstyle = newShellStyle & ~SWT.APPLICATION_MODAL; - // // turn on MODELESS - // newstyle |= SWT.MODELESS; - // super.setShellStyle(newstyle); - // } - // - // public int open() { - // - // int retVal = super.open(); - // // this will let the caller wait till OK, Cancel is - // // pressed, but will let the other GUI responsive - // pumpMessages(); - // return retVal; - // } - // - // protected void pumpMessages() { - // Shell sh = getShell(); - // Display disp = sh.getDisplay(); - // while (!sh.isDisposed()) { - // if (!disp.readAndDispatch()) - // disp.sleep(); - // } - // disp.update(); - // } - }