Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Nebula LoginDialog"

m
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
 +
[[Nebula|< Back to Nebula Main Page]]
 +
 
==Introduction==
 
==Introduction==
  
Line 6: Line 8:
  
 
This component is very simple and present a simple and flexible dialog box to authentify a user. It is inspired by the SwingX component.
 
This component is very simple and present a simple and flexible dialog box to authentify a user. It is inspired by the SwingX component.
 +
 
__TOC__
 
__TOC__
  
 
==Usage==
 
==Usage==
  
The first thing to do is to create a '''Verifier''' by instancing a object that implements the interface <code>LoginDialogVerifier</code>.
+
The first thing to do is to create a <code>Verifier</code> by instancing a object that implements the interface <code>LoginDialogVerifier</code>.
  
 
This interface contains one method :  
 
This interface contains one method :  
Line 18: Line 21:
 
In the implementation of this method, you put the code to authenticate the user (LDAP, DB, ...). If the couple login/password is incorrect or if something goes wrong (Database lost for example), the method throws an Exception. The detail message contains the description of the error :
 
In the implementation of this method, you put the code to authenticate the user (LDAP, DB, ...). If the couple login/password is incorrect or if something goes wrong (Database lost for example), the method throws an Exception. The detail message contains the description of the error :
  
final LoginDialogVerifier verifier = new LoginDialogVerifier() {
+
final LoginDialogVerifier verifier = new LoginDialogVerifier() {
 
+
+
 
+
Then, you create a LoginDialog object, you inject the verifier and you call the open() methods that returns true if the couple login/password is correct, or false if the user pressed on the cancel button.
+
  
<code>  
+
Then, you create a <code>LoginDialog</code> object, you inject the verifier and you call the <code>open()</code> methods that returns <code>true</code> if the couple login/password is correct, or <code>false</code> if the user pressed on the cancel button.
<nowiki>final LoginDialog dialog = new LoginDialog();
+
dialog.setVerifier(verifier);
+
  
final boolean result = dialog.open();
+
final LoginDialog dialog = new LoginDialog();
if (result) {
+
dialog.setVerifier(verifier);
System.out.println("Login confirmed : " + dialog.getLogin());
+
} else {
+
final boolean result = dialog.open();
System.out.println("User canceled !");
+
if (result) {
}
+
      System.out.println("Login confirmed : " + dialog.getLogin());
</nowiki></code>
+
} else {
 +
      System.out.println("User canceled !");
 +
}
  
 
You can customize the dialog box by setting the following properties :
 
You can customize the dialog box by setting the following properties :
Line 48: Line 47:
 
An example called LoginDialogSnippet.java is available in the plugin org.eclipse.nebula.widgets.opal.logindialog.snippets.
 
An example called LoginDialogSnippet.java is available in the plugin org.eclipse.nebula.widgets.opal.logindialog.snippets.
  
This example is also available here : https://github.com/lcaron/opal/blob/master/src/test/java/org/mihalis/opal/login/LoginDialogSnippet.java
+
This example is also available here : [https://github.com/eclipse/nebula/blob/master/widgets/opal/logindialog/org.eclipse.nebula.widgets.opal.logindialog.snippets/src/org/eclipse/nebula/widgets/opal/loginDialog/snippets/LoginDialogSnippet.java LoginDialogSnippet.java]

Latest revision as of 06:43, 19 March 2020

< Back to Nebula Main Page

Introduction

Login1.png

Login2.png

This component is very simple and present a simple and flexible dialog box to authentify a user. It is inspired by the SwingX component.

Usage

The first thing to do is to create a Verifier by instancing a object that implements the interface LoginDialogVerifier.

This interface contains one method :

public void authenticate(final String login, final String password) throws Exception

In the implementation of this method, you put the code to authenticate the user (LDAP, DB, ...). If the couple login/password is incorrect or if something goes wrong (Database lost for example), the method throws an Exception. The detail message contains the description of the error :

final LoginDialogVerifier verifier = new LoginDialogVerifier() {

Then, you create a LoginDialog object, you inject the verifier and you call the open() methods that returns true if the couple login/password is correct, or false if the user pressed on the cancel button.

final LoginDialog dialog = new LoginDialog();
dialog.setVerifier(verifier);

final boolean result = dialog.open();
if (result) {
     System.out.println("Login confirmed : " + dialog.getLogin());
} else {
     System.out.println("User canceled !");
}

You can customize the dialog box by setting the following properties :

  • image. By default, the header image is a blue wave with a title
  • description. A text located between the header and the login text box
  • login, password
  • autorizedLogin, if you want to limit the login to a set of users. In this case, the login text box will be replaced by a combo.
  • displayRememberPassword. If true, a checkbox "Remember my password" is displayed. In this case, you can get/set the checkbox by manipulating the property rememberPassword.

Example

An example called LoginDialogSnippet.java is available in the plugin org.eclipse.nebula.widgets.opal.logindialog.snippets.

This example is also available here : LoginDialogSnippet.java

Back to the top