From: Mathieu Baudier Date: Thu, 15 Oct 2015 14:35:37 +0000 (+0000) Subject: Can extends login credentials block. X-Git-Tag: argeo-commons-2.1.30~85 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;h=a0cb2f599e0f63b29c7e7a3f0dffde69726241bf;p=lgpl%2Fargeo-commons.git Can extends login credentials block. git-svn-id: https://svn.argeo.org/commons/trunk@8492 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/org.argeo.cms/src/org/argeo/cms/widgets/auth/CmsLogin.java b/org.argeo.cms/src/org/argeo/cms/widgets/auth/CmsLogin.java index 53a23a324..1220c12a2 100644 --- a/org.argeo.cms/src/org/argeo/cms/widgets/auth/CmsLogin.java +++ b/org.argeo.cms/src/org/argeo/cms/widgets/auth/CmsLogin.java @@ -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 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; diff --git a/org.argeo.cms/src/org/argeo/cms/widgets/auth/CmsLoginShell.java b/org.argeo.cms/src/org/argeo/cms/widgets/auth/CmsLoginShell.java index 9f89f128a..66dc5a673 100644 --- a/org.argeo.cms/src/org/argeo/cms/widgets/auth/CmsLoginShell.java +++ b/org.argeo.cms/src/org/argeo/cms/widgets/auth/CmsLoginShell.java @@ -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. */ diff --git a/org.argeo.security.ui.rap/src/org/argeo/security/ui/rap/RapWorkbenchLogin.java b/org.argeo.security.ui.rap/src/org/argeo/security/ui/rap/RapWorkbenchLogin.java index 8c380bd3e..789874ae3 100644 --- a/org.argeo.security.ui.rap/src/org/argeo/security/ui/rap/RapWorkbenchLogin.java +++ b/org.argeo.security.ui.rap/src/org/argeo/security/ui/rap/RapWorkbenchLogin.java @@ -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); + } + } diff --git a/org.argeo.security.ui.rap/src/org/argeo/security/ui/rap/WorkbenchLogin.java b/org.argeo.security.ui.rap/src/org/argeo/security/ui/rap/WorkbenchLogin.java index 2a98c6c9f..a074ed956 100644 --- a/org.argeo.security.ui.rap/src/org/argeo/security/ui/rap/WorkbenchLogin.java +++ b/org.argeo.security.ui.rap/src/org/argeo/security/ui/rap/WorkbenchLogin.java @@ -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 diff --git a/org.argeo.util/src/org/argeo/util/LocaleChoice.java b/org.argeo.util/src/org/argeo/util/LocaleChoice.java index 4b4db0eca..e9d9acac4 100644 --- a/org.argeo.util/src/org/argeo/util/LocaleChoice.java +++ b/org.argeo.util/src/org/argeo/util/LocaleChoice.java @@ -88,6 +88,10 @@ public class LocaleChoice { this.selectedIndex = selectedIndex; } + public Integer getSelectedIndex() { + return selectedIndex; + } + public Integer getDefaultIndex() { return defaultIndex; }