Can extends login credentials block.
authorMathieu Baudier <mbaudier@argeo.org>
Thu, 15 Oct 2015 14:35:37 +0000 (14:35 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Thu, 15 Oct 2015 14:35:37 +0000 (14:35 +0000)
git-svn-id: https://svn.argeo.org/commons/trunk@8492 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

org.argeo.cms/src/org/argeo/cms/widgets/auth/CmsLogin.java
org.argeo.cms/src/org/argeo/cms/widgets/auth/CmsLoginShell.java
org.argeo.security.ui.rap/src/org/argeo/security/ui/rap/RapWorkbenchLogin.java
org.argeo.security.ui.rap/src/org/argeo/security/ui/rap/WorkbenchLogin.java
org.argeo.util/src/org/argeo/util/LocaleChoice.java

index 53a23a3243a995b3ee705f7adce589dc24a921a1..1220c12a28430d3a59562eb469f292c29e89725b 100644 (file)
@@ -48,8 +48,10 @@ import org.eclipse.swt.widgets.Shell;
 import org.eclipse.swt.widgets.Text;
 
 public class CmsLogin implements CmsStyles, CallbackHandler {
+       private Composite parent;
        private Text usernameT, passwordT;
        private Composite credentialsBlock;
+       private final SelectionListener loginSelectionListener;
 
        private final Locale defaultLocale;
        private LocaleChoice localeChoice = null;
@@ -62,13 +64,30 @@ public class CmsLogin implements CmsStyles, CallbackHandler {
                List<Locale> locales = getKernelHeader().getLocales();
                if (locales != null)
                        localeChoice = new LocaleChoice(locales, defaultLocale);
+               loginSelectionListener = new SelectionListener() {
+                       private static final long serialVersionUID = -8832133363830973578L;
+
+                       @Override
+                       public void widgetSelected(SelectionEvent e) {
+                               login();
+                       }
+
+                       @Override
+                       public void widgetDefaultSelected(SelectionEvent e) {
+                       }
+               };
        }
 
        protected boolean isAnonymous() {
                return CurrentUser.isAnonymous(cmsView.getSubject());
        }
 
-       public void createContents(Composite parent) {
+       public final void createUi(Composite parent) {
+               this.parent = parent;
+               createContents(parent);
+       }
+
+       protected void createContents(Composite parent) {
                defaultCreateContents(parent);
        }
 
@@ -123,6 +142,8 @@ public class CmsLogin implements CmsStyles, CallbackHandler {
        }
 
        protected Composite anonymousUi(Composite parent) {
+               Locale locale = localeChoice == null ? this.defaultLocale
+                               : localeChoice.getSelectedLocale();
                // We need a composite for the traversal
                credentialsBlock = new Composite(parent, SWT.NONE);
                credentialsBlock.setLayout(new GridLayout());
@@ -133,7 +154,7 @@ public class CmsLogin implements CmsStyles, CallbackHandler {
 
                // new Label(this, SWT.NONE).setText(CmsMsg.username.lead());
                usernameT = new Text(credentialsBlock, SWT.BORDER);
-               usernameT.setMessage(username.lead(defaultLocale));
+               usernameT.setMessage(username.lead(locale));
                usernameT.setData(RWT.CUSTOM_VARIANT, CMS_LOGIN_DIALOG_USERNAME);
                GridData gd = CmsUtils.fillWidth();
                gd.widthHint = textWidth;
@@ -141,7 +162,7 @@ public class CmsLogin implements CmsStyles, CallbackHandler {
 
                // new Label(this, SWT.NONE).setText(CmsMsg.password.lead());
                passwordT = new Text(credentialsBlock, SWT.BORDER | SWT.PASSWORD);
-               passwordT.setMessage(password.lead(defaultLocale));
+               passwordT.setMessage(password.lead(locale));
                passwordT.setData(RWT.CUSTOM_VARIANT, CMS_LOGIN_DIALOG_PASSWORD);
                gd = CmsUtils.fillWidth();
                gd.widthHint = textWidth;
@@ -160,13 +181,36 @@ public class CmsLogin implements CmsStyles, CallbackHandler {
                passwordT.addTraverseListener(tl);
                parent.setTabList(new Control[] { credentialsBlock });
                credentialsBlock.setTabList(new Control[] { usernameT, passwordT });
-               credentialsBlock.setFocus();
+               // credentialsBlock.setFocus();
 
+               extendsCredentialsBlock(credentialsBlock, locale,
+                               loginSelectionListener);
                if (localeChoice != null)
                        createLocalesBlock(credentialsBlock);
                return credentialsBlock;
        }
 
+       /**
+        * To be overridden in order to provide custome login button and other
+        * links.
+        */
+       protected void extendsCredentialsBlock(Composite credentialsBlock,
+                       Locale selectedLocale, SelectionListener loginSelectionListener) {
+
+       }
+
+       protected void updateLocale(Locale selectedLocale) {
+               // usernameT.setMessage(username.lead(selectedLocale));
+               // passwordT.setMessage(password.lead(selectedLocale));
+               for (Control child : parent.getChildren())
+                       child.dispose();
+               createContents(parent);
+               if (parent.getParent() != null)
+                       parent.getParent().layout();
+               else
+                       parent.layout();
+       }
+
        protected Composite createLocalesBlock(final Composite parent) {
                Composite c = new Composite(parent, SWT.NONE);
                c.setLayout(CmsUtils.noSpaceGridLayout());
@@ -176,10 +220,12 @@ public class CmsLogin implements CmsStyles, CallbackHandler {
                        private static final long serialVersionUID = 4891637813567806762L;
 
                        public void widgetSelected(SelectionEvent event) {
-                               localeChoice.setSelectedIndex((Integer) event.widget.getData());
-                               Locale selectedLocale = localeChoice.getSelectedLocale();
-                               usernameT.setMessage(username.lead(selectedLocale));
-                               passwordT.setMessage(password.lead(selectedLocale));
+                               Button button = (Button) event.widget;
+                               if (button.getSelection()) {
+                                       localeChoice.setSelectedIndex((Integer) event.widget
+                                                       .getData());
+                                       updateLocale(localeChoice.getSelectedLocale());
+                               }
                        };
                };
 
@@ -192,7 +238,7 @@ public class CmsLogin implements CmsStyles, CallbackHandler {
                                        + " (" + locale + ")");
                        // button.addListener(SWT.Selection, listener);
                        button.addSelectionListener(selectionListener);
-                       if (i == localeChoice.getDefaultIndex())
+                       if (i == localeChoice.getSelectedIndex())
                                button.setSelection(true);
                }
                return c;
index 9f89f128af0a2d9f26a2753a1d478e29174a6985..66dc5a673fbd0bfe37d762d5c0c06396a6e7ca24 100644 (file)
@@ -14,7 +14,7 @@ public class CmsLoginShell extends CmsLogin {
                super(cmsView);
                shell = createShell();
                shell.setData(RWT.CUSTOM_VARIANT, CMS_USER_MENU);
-               createContents(shell);
+               createUi(shell);
        }
 
        /** To be overridden. */
index 8c380bd3ed991d38aec307f737b7f851fb777dc0..789874ae3c8b559a2b956eda0cec56280f140408 100644 (file)
@@ -1,7 +1,15 @@
 package org.argeo.security.ui.rap;
 
+import java.util.Locale;
+
+import org.argeo.cms.CmsMsg;
+import org.argeo.cms.util.CmsUtils;
 import org.eclipse.rap.rwt.RWT;
 import org.eclipse.rap.rwt.client.service.JavaScriptExecutor;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.ui.PlatformUI;
 
@@ -34,4 +42,13 @@ public class RapWorkbenchLogin extends WorkbenchLogin {
                return returnCode;
        }
 
+       @Override
+       protected void extendsCredentialsBlock(Composite credentialsBlock,
+                       Locale selectedLocale, SelectionListener loginSelectionListener) {
+               Button loginButton = new Button(credentialsBlock, SWT.PUSH);
+               loginButton.setText(CmsMsg.login.lead(selectedLocale));
+               loginButton.setLayoutData(CmsUtils.fillWidth());
+               loginButton.addSelectionListener(loginSelectionListener);
+       }
+
 }
index 2a98c6c9ff767f5185ce418989b97ab95a6fba37..a074ed956dc1f0ad033356a9a87bb4b7a8cc42ca 100644 (file)
@@ -1,6 +1,7 @@
 package org.argeo.security.ui.rap;
 
 import java.security.PrivilegedAction;
+import java.util.Locale;
 
 import javax.security.auth.Subject;
 import javax.security.auth.login.CredentialNotFoundException;
@@ -21,6 +22,7 @@ import org.argeo.eclipse.ui.dialogs.ErrorFeedback;
 import org.argeo.eclipse.ui.specific.UiContext;
 import org.eclipse.rap.rwt.RWT;
 import org.eclipse.rap.rwt.application.EntryPoint;
+import org.eclipse.swt.events.SelectionListener;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.ui.PlatformUI;
@@ -91,8 +93,17 @@ abstract class WorkbenchLogin implements EntryPoint, CmsView {
 
                        @Override
                        public void createContents(Composite parent) {
-                               createLoginPage(parent, this);
+                               WorkbenchLogin.this.createLoginPage(parent, this);
                        }
+
+                       @Override
+                       protected void extendsCredentialsBlock(Composite credentialsBlock,
+                                       Locale selectedLocale,
+                                       SelectionListener loginSelectionListener) {
+                               WorkbenchLogin.this.extendsCredentialsBlock(credentialsBlock,
+                                               selectedLocale, loginSelectionListener);
+                       }
+
                };
        }
 
@@ -106,6 +117,11 @@ abstract class WorkbenchLogin implements EntryPoint, CmsView {
                login.defaultCreateContents(parent);
        }
 
+       protected void extendsCredentialsBlock(Composite credentialsBlock,
+                       Locale selectedLocale, SelectionListener loginSelectionListener) {
+
+       }
+
        @Override
        public void navigateTo(String state) {
                // TODO Auto-generated method stub
index 4b4db0eca257ac6e1c78f84a775f7e26d98462e6..e9d9acac4f6f47ea5932f1c3a9e46f6e757596fd 100644 (file)
@@ -88,6 +88,10 @@ public class LocaleChoice {
                this.selectedIndex = selectedIndex;
        }
 
+       public Integer getSelectedIndex() {
+               return selectedIndex;
+       }
+
        public Integer getDefaultIndex() {
                return defaultIndex;
        }