Skip to main content



      Home
Home » Eclipse Projects » Rich Client Platform (RCP) » User Name and Password
User Name and Password [message #460906] Tue, 02 January 2007 10:43 Go to next message
Eclipse UserFriend
Hi Everyone,

I would like to create Username and password window to provide a basic auth to my app, I created the GUI for it (look below), however I am not sure where shall I call it (Application.java?) and how to start up the application if the username and the password is right!?

package net.dresdnerkleinwort.hierarchy.client;


import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class UserPassword {
Display display = new Display();
Shell shell = new Shell(display);

Text textUser;
Text textPassword;

private void init() {
(new Label(shell, SWT.NULL)).setText("User name: ");

textUser = new Text(shell, SWT.SINGLE | SWT.BORDER);
textUser.setText("default_user");
textUser.setTextLimit(16);

(new Label(shell, SWT.NULL)).setText("Password: ");

textPassword = new Text(shell, SWT.SINGLE | SWT.BORDER);
System.out.println(textPassword.getEchoChar());
textPassword.setEchoChar('*');
}

public UserPassword() {
shell.setLayout(new GridLayout(2, false));
shell.setText("Hierarchy Manager Login");
init();

textUser.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
textPassword.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

shell.pack();
shell.setSize(280, 100);
shell.open();
//textUser.forceFocus();

// Set up the event loop.
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
// If no more entries in event queue
display.sleep();
}
}

display.dispose();
}



public static void main(String[] args) {
new UserPassword();
}
}
Re: User Name and Password [message #460941 is a reply to message #460906] Tue, 02 January 2007 12:52 Go to previous messageGo to next message
Eclipse UserFriend
Ali Alauoubiy wrote:
> Hi Everyone,
>
> I would like to create Username and password window to provide a basic auth to my app, I created the GUI for it (look below), however I am not sure where shall I call it (Application.java?) and how to start up the application if the username and the password is right!?
>

Ali,

I'm doing this in one of my own applications. In my application, I have
to check for a valid license to the software right at startup. I
extended ApplicationWindow from JFace for my main window, and added a
SWT.Activate listener to the shell in the configureShell(Shell) method:

shell.addListener(SWT.Activate, new Listener() {
public void handleEvent(Event event) {
License license = getProductLicense();
if (license == null || !license.isActive()) {
license = showLicenseDialog();
if (license == null || !license.isActive())
shell.close();
}
}
});

I have some more stuff in there that warns the user when the software
will expire, but you get the basic idea. This code will run every time
the window is activated (which happens when the window first appears,
and again every time you leave the window and return to it).

Another option is to prompt for the user's credentials before the main
window ever appears, probably right before calling shell.open() on your
main window. Does this help?

Matthew
Re: User Name and Password [message #460955 is a reply to message #460906] Tue, 02 January 2007 16:37 Go to previous message
Eclipse UserFriend
Hi,

I call my login dialog in the postWindowOpen method of my application's
WorkbenchWindowAdvisor. That way, it is show after the workbench is opened.

Here is my code:

public void postWindowOpen() {
super.postWindowOpen();
/* Hide the splash screen*/
Platform.endSplash();
/* Show the login dialog */
showLogin();
}

The dialog is a modal dialog.

Regards,

Camilo.
Previous Topic:How to rearrange views programmatically?
Next Topic:Context Sensitive Help
Goto Forum:
  


Current Time: Thu Mar 20 08:46:09 EDT 2025

Powered by FUDForum. Page generated in 0.02843 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top