]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/dialogs/DefaultLoginDialog.java
IMprove centering of defualt login dialog in RCP
[lgpl/argeo-commons.git] / security / plugins / org.argeo.security.ui / src / main / java / org / argeo / security / ui / dialogs / DefaultLoginDialog.java
index 208eefea8b1b84a644552b4ad485cf0df7487a7e..dc7c09a990dd9c445e1765564381b3c56100f70f 100644 (file)
@@ -1,3 +1,18 @@
+/*
+ * 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;
@@ -39,8 +54,13 @@ 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();
+               Rectangle shellBounds;
+               if (Display.getCurrent().getActiveShell() != null) // RCP
+                       shellBounds = Display.getCurrent().getActiveShell().getBounds();
+               else
+                       shellBounds = Display.getCurrent().getBounds();// RAP
                Point dialogSize = parent.getSize();
                int x = shellBounds.x + (shellBounds.width - dialogSize.x) / 2;
                int y = shellBounds.y + (shellBounds.height - dialogSize.y) / 2;
@@ -96,6 +116,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() {