Skip to content

Commit

Permalink
Merge pull request #8 from KlasJoenssson/NewLoginDialog
Browse files Browse the repository at this point in the history
New login dialog
  • Loading branch information
jonalv committed Mar 20, 2012
2 parents 51b3f45 + 69441b2 commit aabdde8
Show file tree
Hide file tree
Showing 5 changed files with 480 additions and 65 deletions.
@@ -0,0 +1,65 @@
/* *****************************************************************************
* Copyright (c) 2007-2009 Bioclipse Project
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
*
*******************************************************************************/
package net.bioclipse.usermanager;

import net.bioclipse.usermanager.dialogs.DialogArea;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.widgets.Composite;

/**
* This is the wizard page for log-in into Bioclipse.
*
* @author Klas Jšnsson (aka "konditorn")
*
*/
public class LoginWizardPage extends WizardPage {

private DialogArea loginDialogArea;

protected LoginWizardPage(String pageName, UserContainer userContainer) {
super(pageName);
this.loginDialogArea = new DialogArea(userContainer ,true, this);
}

@Override
public void createControl(Composite parent) {
Composite container = loginDialogArea.getLoginArea(parent);
setControl(container);
setErrorMessage(loginDialogArea.getErrorMessage());
}

@Override
public boolean isPageComplete() {
return !loginDialogArea.getErrorFlag();
}

/**
* This method just passes on the username written in the text-field in the
* login dialog.
*
* @return The username
*/
public String getUsername() {
return loginDialogArea.getUsername();
}
/**
* This method just passes on the password written in the text-field in the
* login dialog.
*
* @return The password
*/
public String getPassword() {
return loginDialogArea.getPassword();

}

}

Expand Up @@ -10,17 +10,27 @@
******************************************************************************/
package net.bioclipse.usermanager;

import net.bioclipse.core.util.LogUtils;
import net.bioclipse.usermanager.business.IUserManager;
import net.bioclipse.usermanager.dialogs.CreateUserDialog;
import net.bioclipse.usermanager.dialogs.LoginDialog;

import org.apache.log4j.Logger;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.window.Window;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.handlers.IHandlerService;

/**
* A wizard for handling the users third parts accounts
Expand All @@ -30,75 +40,143 @@
*/
public class NewAccountWizard extends Wizard implements INewWizard {

private NewAccountWizardPage mainPage;
private static final Logger logger
= Logger.getLogger(LoginDialog.class);

private NewAccountWizardPage addAccountPage;
private LoginWizardPage loginPage;

public NewAccountWizard() {
boolean cancel = false;
IUserManager usermanager = Activator.getDefault().getUserManager();
if (usermanager.getUserNames().size() == 0) {
UserContainer sandbox = usermanager.getSandBoxUserContainer();
CreateUserDialog dialog
= new CreateUserDialog( PlatformUI.getWorkbench()
.getActiveWorkbenchWindow()
.getShell(), sandbox );
dialog.open();
if (dialog.getReturnCode() == dialog.OK) {
usermanager.switchUserContainer( sandbox );
}
else if (dialog.getReturnCode() == dialog.CANCEL) {
cancel = true;
}
}

if ( !cancel && !usermanager.isLoggedIn() ) {
UserContainer sandbox = usermanager.getSandBoxUserContainer();
LoginDialog loginDialog
= new LoginDialog( PlatformUI.getWorkbench()
.getActiveWorkbenchWindow()
.getShell(),
sandbox );

loginDialog.open();
if ( loginDialog.getReturnCode() == LoginDialog.OK ) {
if ( loginDialog.isUserContainerEdited() ) {
Activator.getDefault().getUserManager()
.switchUserContainer(sandbox);
}
}
}
IUserManager usermanager = Activator.getDefault().getUserManager();
if (usermanager.getUserNames().size() == 0) {
UserContainer sandbox = usermanager.getSandBoxUserContainer();
CreateUserDialog dialog
= new CreateUserDialog( PlatformUI.getWorkbench()
.getActiveWorkbenchWindow()
.getShell(), sandbox );
dialog.open();
if (dialog.getReturnCode() == Window.OK) {
usermanager.switchUserContainer( sandbox );
}
else if (dialog.getReturnCode() == Window.CANCEL) {
dispose();
}
}
}

@Override
public void init(IWorkbench workbench, IStructuredSelection selection) {
setWindowTitle("Add an account to Bioclipse");
setNeedsProgressMonitor(true);
setWindowTitle("Add an account to Bioclipse");
setNeedsProgressMonitor(true);
}

public void addPages() {
super.addPages();
// TODO add the Bioclipse create-account and log-in dialogs as pages
// are the any more to be added?
mainPage = new NewAccountWizardPage("mainPage");
mainPage.setTitle("New Account");
mainPage.setDescription("Add a third-part account to Bioclipse");
addPage(mainPage);
setDefaultPageImageDescriptor(ImageDescriptor
.createFromFile(this.getClass(),
"BioclipseAccountLogo3_medium.png"));
}


public void addPages() {
super.addPages();
IUserManager usermanager = Activator.getDefault().getUserManager();
if ( !usermanager.isLoggedIn() ) {
UserContainer sandbox = usermanager.getSandBoxUserContainer();
loginPage = new LoginWizardPage("loginPage", sandbox);
loginPage.setTitle("Log In To Your Bioclipse Account");
loginPage.setDescription("Before adding an acount you have to " +
"loggin or create a new acount.");
addPage(loginPage);
}

addAccountPage = new NewAccountWizardPage("addAccountPage");
addAccountPage.setTitle("New Account");
addAccountPage.setDescription("Add a third-part account to Bioclipse");
addPage(addAccountPage);


setDefaultPageImageDescriptor(ImageDescriptor
.createFromFile(this.getClass(),
"BioclipseAccountLogo3_medium.png"));
}

@Override
public boolean performFinish() {
if (mainPage.createAccount()) {
IUserManager usermanager = Activator.getDefault().getUserManager();
if ( !usermanager.isLoggedIn() ) {
performLogin();
}

if (addAccountPage.createAccount()) {
dispose();
return true;
} else
return false;
}

@Override
public boolean canFinish() {
return mainPage.isPageComplete();
return addAccountPage.isPageComplete();
}

public boolean performCancel() {
return true;
}

/**
* This method log in the user.
*/
private void performLogin() {
final String username = loginPage.getUsername();
final String password = loginPage.getPassword();
Job job = new Job("Signing in " + username) {

@Override
protected IStatus run( IProgressMonitor monitor ) {

try {
int scale = 1000;
monitor.beginTask( "Signing in...",
IProgressMonitor.UNKNOWN );
Activator.getDefault().getUserManager()
.signInWithProgressBar(
username,
password,
new SubProgressMonitor(
monitor,
1 * scale) );
}
catch ( final Exception e ) {
Display.getDefault().asyncExec(new Runnable() {

public void run() {
MessageDialog.openInformation(
PlatformUI
.getWorkbench()
.getActiveWorkbenchWindow()
.getShell(),
"Could not sign in "
+ username,
e.getMessage() );
try {
((IHandlerService)
PlatformUI.getWorkbench()
.getActiveWorkbenchWindow()
.getService(IHandlerService.class) )
.executeCommand(
"net.bioclipse.usermanager" +
".commands.login",
null );
}
catch ( Exception e ) {
LogUtils.handleException(
e,
logger,
"net.bioclipse.usermanager" );
}
}
});
}
finally {
monitor.done();
}
return Status.OK_STATUS;
}
};
job.setUser( true );
job.schedule();
}
}
Expand Up @@ -30,7 +30,7 @@
/**
* The wizard page that handles the different parts accounts.
*
* @author Klas Jšnsson
* @author Klas Jšnsson (aka "konditorn")
*
*/
public class NewAccountWizardPage extends WizardPage implements Listener {
Expand Down Expand Up @@ -95,12 +95,6 @@ public void createControl(Composite parent) {
giveFocus();
}
setControl(container);
if ( !Activator.getDefault().getUserManager().isLoggedIn() ) {
System.out.println("CANCEL!" + this.getWizard().performCancel());
// TODO FIXME find a better way to do this that does not cause an
// Exception.
this.getShell().close();
}
}


Expand Down Expand Up @@ -213,10 +207,13 @@ private String createErrorMessage(ArrayList<String> unfilledFields) {

@Override
public boolean isPageComplete() {
if (addedAccounts.size()>0) {
AccountPropertiesPage account =
addedAccounts.get(accountTypeCombo.getSelectionIndex());
return account.isFieldsProperlyFilled();
if (isCurrentPage()) {
if (addedAccounts.size()>0) {
AccountPropertiesPage account =
addedAccounts.get(accountTypeCombo.getSelectionIndex());
return account.isFieldsProperlyFilled();
} else
return false;
} else
return false;
}
Expand Down

0 comments on commit aabdde8

Please sign in to comment.