Skip to content

Commit

Permalink
Made the login dialog as a part of the wizard, instead of having it as
Browse files Browse the repository at this point in the history
an own dialog.
  • Loading branch information
KlasJoensson committed Mar 19, 2012
1 parent 53f8401 commit e6a66b4
Show file tree
Hide file tree
Showing 5 changed files with 234 additions and 84 deletions.
@@ -1,17 +1,17 @@
package net.bioclipse.usermanager;

import net.bioclipse.usermanager.dialogs.DialogArea;

import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.widgets.Composite;


public class LoginWizardPage extends WizardPage {
private DialogArea loginDialogArea;

private DialogArea loginDialogArea;

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

@Override
Expand All @@ -23,7 +23,17 @@ public void createControl(Composite parent) {

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

public String getUsername() {
return loginDialogArea.getUsername();
}

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,141 @@
*/
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);
}
}
}
// 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() == 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;
}

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 @@ -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 e6a66b4

Please sign in to comment.